From 611409c777771f4e15ced51a587aa215a267c106 Mon Sep 17 00:00:00 2001 From: Henrik Hautakoski Date: Sat, 24 Sep 2011 13:03:22 +0200 Subject: [PATCH] lockfile: expose locked() usefull to have this macro in the interface so other modules using lockfiles can check if a certain lock is active. --- lockfile.c | 8 +++----- lockfile.h | 2 ++ 2 files changed, 5 insertions(+), 5 deletions(-) diff --git a/lockfile.c b/lockfile.c index 77800dd..00dfd60 100644 --- a/lockfile.c +++ b/lockfile.c @@ -30,8 +30,6 @@ #include "error.h" #include "lockfile.h" -#define locked(x) ((x)->fd >= 0) - static struct lockfile *active_locks; static void release_all_locks() { @@ -101,7 +99,7 @@ int hold_lock(struct lockfile *lock, const char *filename, int force) { init(); - if (locked(lock)) + if (is_locked(lock)) return -1; if (!force) @@ -127,7 +125,7 @@ int commit_lock(struct lockfile *lock) { char target[4096]; int len; - if (!locked(lock)) + if (!is_locked(lock)) return 0; len = strlen(lock->name) - 5; /* .lock */ @@ -148,7 +146,7 @@ int release_lock(struct lockfile *lock) { int rc; - if (!locked(lock)) + if (!is_locked(lock)) return 0; rc = unlink(lock->name); if (rc == 0) { diff --git a/lockfile.h b/lockfile.h index a10c90a..1d9bba6 100644 --- a/lockfile.h +++ b/lockfile.h @@ -31,6 +31,8 @@ struct lockfile { #define LOCKFILE_INIT { 0, -1, { 0 } } +#define is_locked(x) ((x)->fd >= 0) + int hold_lock(struct lockfile *lock, const char *filename, int force); int commit_lock(struct lockfile *lock);