From 90b819c6d832046840018ff08b9bc5d0e3b69c37 Mon Sep 17 00:00:00 2001 From: Laurent Bercot Date: Sun, 29 Nov 2020 21:02:32 +0000 Subject: Revamp lock primitives; prepare for 2.10.0.0 instead of 2.9.4.0 flock() doesn't have a way to test for a lock without taking it. lockf() doesn't have shared locks. The only way to have both is fcntl(). So I rewrote all the locking stuff around fcntl(), and used the opportunity to change the interface. The point of changing the interface is to stop having to bother with the old one, so to hell with compatibility, let's just do a major bump. --- doc/libstddjb/djbunix.html | 45 +++++++++++++-------------------------------- 1 file changed, 13 insertions(+), 32 deletions(-) (limited to 'doc/libstddjb/djbunix.html') diff --git a/doc/libstddjb/djbunix.html b/doc/libstddjb/djbunix.html index e70fe4f..54aaf50 100644 --- a/doc/libstddjb/djbunix.html +++ b/doc/libstddjb/djbunix.html @@ -202,45 +202,26 @@ with errno saved, used essentially to isolate application code from

- int lock_ex (int fd)
-Gets an exclusive advisory lock on fd. fd must point to -a regular file, open for writing. Blocks until the lock can be obtained. -Returns 0 if it succeeds, or -1 (and sets errno) if it fails. -

- -

- int lock_exnb (int fd)
-Gets an exclusive advisory lock on fd. fd must point to -a regular file, open for writing. -Returns 0 if it succeeds, or -1 (and sets errno) if it fails. If the lock -is held and the function would block, it immediately returns with -1 EWOULDBLOCK. -

- -

- int lock_sh (int fd)
-Gets a shared advisory lock on fd. fd must point to -a regular file, open for reading. Blocks until the lock can be obtained. -Returns 0 if it succeeds, or -1 (and sets errno) if it fails. -

- -

- int lock_shnb (int fd)
-Gets a shared advisory lock on fd. fd must point to -a regular file, open for reading. -Returns 0 if it succeeds, or -1 (and sets errno) if it fails. If the lock -is held and the function would block, it immediately returns with -1 EWOULDBLOCK. + int fd_lock (int fd, int w, int nb)
+Gets an advisory lock on fd: shared if w is +zero, exclusive otherwise. fd must point to +a regular file, open for writing or reading depending on whether +you want an exclusive lock or not. If nb is zero, the +function blocks until the lock can be obtained; otherwise it +returns 0 immediately. On success, the function returns 1 ; it +returns 0 if it cannot take the lock, or -1 (and sets errno) if +an error occurs.

- int lock_un (int fd)
+ void fd_unlock (int fd)
Releases a previously held lock on fd. -Returns 0 if it succeeds, or -1 (and sets errno) if it fails.

- void lock_unx (int fd)
-Like lock_un, but without a return code and without -modifying errno. + int fd_islocked (int fd)
+Returns 1 if a lock is currently held on fd, 0 otherwise. +Returns -1 (and sets errno) if an error occurs.

-- cgit v1.2.3