This library uses atomic bit-wise operations on shared memory segment as an internal implementation of locking. Low level functions were infamously stolen from Linux kernel source, thus locking should be even SMP safe. In adition to the lock scopes ( file, record ) and types ( read, write ) provided by the library interface, one ( block ) scope and a few types ( advisory read, advisory write, update, extend and again ) are used internally. Live locks in the shared memory are organized as an ALV tree of file locks containing trees of block locks containing trees of record locks. Pointers used in those trees are not relative. During a lock claiming advisory the lock(s) is/(are) made at upper level(s) e.g. if you need a “record write-lock”, the file and block where the record lives are locked advisory-write.
Example of a successfull locking sequence
When lock can't be obtained (locked by someone else) and if this is first unsucessfull attempt on this lock (nobody is waiting for this lock) library grabs first available semaphore and modifies lock held by other process and sets semaphore up. In all cases library waits until semaphore become zero. This can be only done by the process holding lock.