diff options
author | David Robillard <d@drobilla.net> | 2020-08-05 22:53:33 +0200 |
---|---|---|
committer | David Robillard <d@drobilla.net> | 2020-08-06 17:34:42 +0200 |
commit | 5681c3e2531bbc6768ca850391b63e78aff2f2b2 (patch) | |
tree | 8773d7f93e63343f00d8c9f969475cabfae3bce9 | |
parent | bfe42327cab38b3e47a3b2afec53ea8edd4b1531 (diff) | |
download | lilv-5681c3e2531bbc6768ca850391b63e78aff2f2b2.tar.gz lilv-5681c3e2531bbc6768ca850391b63e78aff2f2b2.tar.bz2 lilv-5681c3e2531bbc6768ca850391b63e78aff2f2b2.zip |
Add block parameter to lilv_flock
-rw-r--r-- | src/filesystem.c | 5 | ||||
-rw-r--r-- | src/filesystem.h | 10 | ||||
-rw-r--r-- | src/state.c | 4 |
3 files changed, 12 insertions, 7 deletions
diff --git a/src/filesystem.c b/src/filesystem.c index a12dcba..6b17ccb 100644 --- a/src/filesystem.c +++ b/src/filesystem.c @@ -270,10 +270,11 @@ lilv_symlink(const char* oldpath, const char* newpath) } int -lilv_flock(FILE* file, bool lock) +lilv_flock(FILE* file, bool lock, bool block) { #if defined(HAVE_FLOCK) && defined(HAVE_FILENO) - return flock(fileno(file), lock ? LOCK_EX : LOCK_UN); + return flock(fileno(file), + (lock ? LOCK_EX : LOCK_UN) | (block ? 0 : LOCK_NB)); #else return 0; #endif diff --git a/src/filesystem.h b/src/filesystem.h index 1b29d42..9cf6e4b 100644 --- a/src/filesystem.h +++ b/src/filesystem.h @@ -88,13 +88,17 @@ lilv_symlink(const char* oldpath, const char* newpath); /** Set or remove an advisory exclusive lock on `file`. - If the `lock` is true and the file is already locked, then this will not - succeed and non-zero will be returned. + If the `lock` is true and the file is already locked by another process, or + by this process via a different file handle, then this will not succeed and + non-zero will be returned. + @param file Handle for open file to lock. + @param lock True to set lock, false to release lock. + @param block If true, then this call will block until the lock is acquired. @return Zero on success. */ int -lilv_flock(FILE* file, bool lock); +lilv_flock(FILE* file, bool lock, bool block); /** Visit every file in the directory at `path`. diff --git a/src/state.c b/src/state.c index 2b7cde9..3086ea6 100644 --- a/src/state.c +++ b/src/state.c @@ -902,7 +902,7 @@ add_state_to_manifest(LilvWorld* lworld, if (rfd) { // Read manifest into model SerdReader* reader = sord_new_reader(model, env, SERD_TURTLE, NULL); - lilv_flock(rfd, true); + lilv_flock(rfd, true, true); serd_reader_read_file_handle(reader, rfd, manifest.buf); serd_reader_free(reader); } @@ -952,7 +952,7 @@ add_state_to_manifest(LilvWorld* lworld, serd_env_free(env); if (rfd) { - lilv_flock(rfd, false); + lilv_flock(rfd, false, true); fclose(rfd); } |