diff options
author | David Hendricks <dhendrix@chromium.org> | 2016-02-25 16:30:41 -0800 |
---|---|---|
committer | chrome-bot <chrome-bot@chromium.org> | 2016-03-01 14:53:50 -0800 |
commit | d89301b0360365306ea7b24751490847858e3646 (patch) | |
tree | b83165c2305ec593a7f8bed71800efd16b181863 /util/lock/ipc_lock.h | |
parent | afc76f1adf97d3a4039663e13afc457139d200fc (diff) | |
download | chrome-ec-d89301b0360365306ea7b24751490847858e3646.tar.gz |
Replace SysV semaphore lock with file lock
Some systems, such as Android, do not support SysV semaphore locks.
This implements an alternative file lock mechanism using flock().
flock() was chosen because it's pretty straight forward. It's known to
be broken when using NFS, but I doubt we'll ever store our lock on an
NFS volume.
CQ-DEPEND=CL:327407,CL:325609
BUG=chrome-os-partner:49527
BRANCH=none
TEST=tested on Smaug by running mosys and ectool while reading
firmware ROM with flashrom, all three utilities eventually
ran successfully.
Change-Id: Ic73fe0281fbc1dfaae1bb03e5683774a0c04ae5b
Signed-off-by: David Hendricks <dhendrix@chromium.org>
Reviewed-on: https://chromium-review.googlesource.com/329430
Reviewed-by: Shawn N <shawnn@chromium.org>
Diffstat (limited to 'util/lock/ipc_lock.h')
-rw-r--r-- | util/lock/ipc_lock.h | 16 |
1 files changed, 7 insertions, 9 deletions
diff --git a/util/lock/ipc_lock.h b/util/lock/ipc_lock.h index 39ae277a7e..ca739ac04e 100644 --- a/util/lock/ipc_lock.h +++ b/util/lock/ipc_lock.h @@ -31,20 +31,18 @@ #ifndef __UTIL_IPC_LOCK_H #define __UTIL_IPC_LOCK_H -#include <sys/ipc.h> - struct ipc_lock { - key_t key; /* provided by the developer */ - int sem; /* internal */ - int is_held; /* internal */ + int is_held; /* internal */ + char *filename; /* provided by the developer */ + int fd; /* internal */ }; /* don't use C99 initializers here, so this can be used in C++ code */ -#define IPC_LOCK_INIT(key) \ +#define LOCKFILE_INIT(lockfile) \ { \ - key, /* name */ \ - -1, /* sem */ \ - 0, /* is_held */ \ + 0, /* is_held */ \ + lockfile, /* filename */ \ + -1, /* fd */ \ } /* |