]> git.ipfire.org Git - thirdparty/samba.git/commit
lib: Change the g_lock data model
authorVolker Lendecke <vl@samba.org>
Tue, 19 Nov 2019 16:29:18 +0000 (17:29 +0100)
committerJeremy Allison <jra@samba.org>
Fri, 22 Nov 2019 23:57:48 +0000 (23:57 +0000)
commitd734547488c6fab8d136239a95db640df57dbb97
tree097fcf015a85d929db1d10dd36f000e5c1e9e17c
parenteffad89f6224fbaeed5ef67016bd23e645763bc9
lib: Change the g_lock data model

Now we have one fixed field for the exclusive lock holder and an array
of shared locks. This way we now prioritize writers over readers: If a
pending write comes in while readers are active, it will put itself
into the exclusive slot. Then it waits for the readers to vanish. Only
when all readers are gone the exclusive lock request is granted. New
readers will just look at the exclusive slot and see it's taken. They
will then line up as watchers, retrying whenever things change.

This also means that it will be cheaper to support many shared locks:
Granting a shared lock just means to extend the array. We don't have
to walk the array for possible conflicts.

This also adds explicit UPGRADE and DOWNGRADE operations for better
error checking.

Signed-off-by: Volker Lendecke <vl@samba.org>
Reviewed-by: Jeremy Allison <jra@samba.org>
source3/include/g_lock.h
source3/lib/g_lock.c
source3/smbd/server.c
source3/torture/test_g_lock.c