cp_splaytree_wrlock(3) - Linux man page
Name
cp_splaytree_lock, cp_splaytree_rdlock, cp_splaytree_wrlock, cp_splaytree_unlock - acquire / release a
lock on an splay tree
Synopsis
#include <cprops/splay.h>
int cp_splaytree_lock(cp_splaytree *tree, int type);
int cp_splaytree_rdlock(cp_splaytree *tree);
int cp_splaytree_wrlock(cp_splaytree *tree);
int cp_splaytree_unlock(cp_splaytree *tree);
Description
cp_splaytree_lock locks the tree for reading if type is
COLLECTION_LOCK_READ or for writing if type is COLLECTION_LOCK_WRITE. The tree mode may not have COLLECTION_MODE_NOSYNC set prior
to locking. Explicit locking isn't required for single tree operations (insertion, retrieval, deletion) which perform locking on their own but rather for
transaction-like operations. To prevent other threads from accessing the tree while performing a series of mapping insertion, removal and lookup operations,
the tree must be explicitly locked first. Tree operation functions will not attempt locking if the current thread owns the tree lock. This prevents deadlocks
but leaves the responsibility for using the correct kind of locking with the application: if there's any possibility the application could change the tree
structure in the transaction, the tree must be write locked. Actions which change the tree structure are insertion and deletion, and, in the case of splay
trees, lookups as well. The cp_splaytree_callback functions however scan the tree structure without changing mapping ordering and could be read-locked.
Calls to cp_splaytree_lock must be coupled with calls to cp_splaytree_unlock after the operation is completed.
cp_splaytree_rdlock(tree) is a synonym for cp_splaytree_lock(tree, COLLECTION_LOCK_READ).
cp_splaytree_wrlock(tree) is a synonym for cp_splaytree_lock(tree, COLLECTION_LOCK_WRITE).
Return Value
cp_splaytree_lock, cp_splaytree_rdlock and cp_splaytree_wrlock return 0
on success, EINVAL if COLLECTION_MODE_NOSYNC is set or -1 if locking fails.
cp_splaytree_unlock returns 0 on success or -1 if unlocking fails.
See Also
cp_splaytree_set_mode(3), cp_splaytree_insert(3)