[cmake-developers] New command 'file(LOCK_DIRECTORY ...)'
Ruslan Baratov
ruslan_baratov at yahoo.com
Wed Dec 17 16:58:33 EST 2014
On 17-Dec-14 21:11, Matthew Woehlke wrote:
> On 2014-10-13 10:39, Brad King wrote:
>> On 10/10/2014 07:45 AM, Ruslan Baratov wrote:
>>> Locking directory is equivalent to locking file `cmake.lock` in
>>> directory "/path/to/shared/directory/":
>> I think this can be activated buy a DIRECTORY option.
> Why do we need even that? Can't CMake just test if the lock target is a
> directory?
I've used boost.interprocess as a hint for implementation, as far as I
know boost::interprocess::file_lock is not able to lock directories:
terminate called after throwing an instance of
'boost::interprocess::interprocess_exception'
what(): Is a directory
I'm not saying that it's not possible, just trying to use well-known
cross-platform solution.
> p.s. For a lock with no timeout, maybe there can be a built-in timeout
> after which CMake displays a message what it's trying to do, so that it
> doesn't just hang mysteriously.
You can use `message` command:
message(STATUS "Try to lock ${file}")
file(LOCK ${file})
or more complex (more user-friendly):
while(TRUE)
file(LOCK "${file}" RESULT is_locked TIMEOUT 5)
if(is_locked)
message("Locked. ${resource_info}")
break()
endif()
string(TIMESTAMP time_now "%S/%M")
message("[${time_now}] Lock failed, retry... (file: ${file})")
endwhile()
Ruslo
More information about the cmake-developers
mailing list