New modes, including a retry mode (the default), removed fcntl
and stub read/write lock mode. New function, to remove a lock even if not owned (useful for the external dotlock utility). New functions, to set the expire time for MU_LOCKER_TIME, the flags, and the retries and retry sleep for MU_LOCKER_RETRY.
Showing
2 changed files
with
36 additions
and
10 deletions
... | @@ -28,23 +28,49 @@ extern "C" { | ... | @@ -28,23 +28,49 @@ extern "C" { |
28 | struct _locker; | 28 | struct _locker; |
29 | typedef struct _locker *locker_t; | 29 | typedef struct _locker *locker_t; |
30 | 30 | ||
31 | extern int locker_create __P ((locker_t *, const char *filename, | 31 | /* lock expiry time */ |
32 | size_t len, int flags)); | 32 | #define MU_LOCKER_EXPIRE_TIME (10 * 60) |
33 | #define MU_LOCKER_RETRIES (10) | ||
34 | #define MU_LOCKER_RETRY_SLEEP (1) | ||
35 | |||
36 | /* locker_create() flags */ | ||
37 | |||
38 | #define MU_LOCKER_RETRY 0x01 | ||
39 | /* This requests that we loop retries times, sleeping retry_sleep | ||
40 | seconds in between trying to obtain the lock before failing with | ||
41 | MU_LOCK_CONFLICT. */ | ||
42 | #define MU_LOCKER_TIME 0x02 | ||
43 | /* This mode checks the last update time of the lock, then removes | ||
44 | it if older than MU_LOCKER_EXPIRE_TIME. If a client uses this, | ||
45 | then the servers better periodically update the lock on the | ||
46 | file... do they? */ | ||
47 | #define MU_LOCKER_PID 0x04 | ||
48 | /* PID locking is only useful for programs that aren't using | ||
49 | an external dotlocker, non-setgid programs will use a dotlocker, | ||
50 | which locks and exits imediately. This is a protection against | ||
51 | a server crashing, it's not generally useful. */ | ||
52 | |||
53 | #define MU_LOCKER_DEFAULT (MU_LOCKER_RETRY) | ||
54 | |||
55 | extern int locker_create __P ((locker_t *, const char *filename, int flags)); | ||
33 | extern void locker_destroy __P ((locker_t *)); | 56 | extern void locker_destroy __P ((locker_t *)); |
34 | 57 | ||
35 | #define MU_LOCKER_RDLOCK 0 | 58 | /* Time is measured in seconds. */ |
36 | #define MU_LOCKER_WRLOCK 1 | ||
37 | 59 | ||
38 | /* locking flags */ | 60 | extern int locker_set_flags __P ((locker_t, int)); |
39 | #define MU_LOCKER_PID 1 | 61 | extern int locker_set_expire_time __P ((locker_t, int)); |
40 | #define MU_LOCKER_FCNTL 2 | 62 | extern int locker_set_retries __P ((locker_t, int)); |
41 | #define MU_LOCKER_TIME 4 | 63 | extern int locker_set_retry_sleep __P ((locker_t, int)); |
42 | 64 | ||
43 | #define MU_LOCKER_EXPIRE_TIME (5 * 60) | 65 | extern int locker_get_flags __P ((locker_t, int*)); |
66 | extern int locker_get_expire_time __P ((locker_t, int*)); | ||
67 | extern int locker_get_retries __P ((locker_t, int*)); | ||
68 | extern int locker_get_retry_sleep __P ((locker_t, int*)); | ||
44 | 69 | ||
45 | extern int locker_lock __P ((locker_t, int flag)); | 70 | extern int locker_lock __P ((locker_t)); |
46 | extern int locker_touchlock __P ((locker_t)); | 71 | extern int locker_touchlock __P ((locker_t)); |
47 | extern int locker_unlock __P ((locker_t)); | 72 | extern int locker_unlock __P ((locker_t)); |
73 | extern int locker_remove_lock __P ((locker_t)); | ||
48 | 74 | ||
49 | #ifdef __cplusplus | 75 | #ifdef __cplusplus |
50 | } | 76 | } | ... | ... |
This diff is collapsed.
Click to expand it.
-
Please register or sign in to post a comment