group
group__libshare__memlock
Provides utility functions to manage mutex thread locks and semaphores.

Mutex and Semaphore Locks

typedef
typedef struct shlock_t shlock_t
The share library lock structure is used primarily in order to prevent multiple threads from performing system calls at the same instance.
The lock includes both re-entrant and private access styles. The functionality can be extended in order to provide custom locks.
See
shlock_open() group__libshare__memlock_1ga671af607715bbe4181e78f174ea13e49 member shlock_close() group__libshare__memlock_1ga837b545d13b80013d1eb6496597e01a4 member
function
shlock_t* shlock_open
(shkey_t *key, int flags)
Create a new lock on a mutex waiting if needed.
Param
num
A positive number identifying the lock.
flags
A set of modifiers to configure the lock. (SHLK_XXX)
Note
The libshare uses negative numbers for internal locks.
See
SHLOCK_SYSTEM group__libshare__memlock_1gaf99dc958d5d8980511586e0c5a41c56e member SHLK_PRIVATE group__libshare__memlock_1ga1115629744ded6de6f3c5d2c51650b7a member
Bug flags should be stored in instead of a paramter shkey_t structshkey__t compound bug_1_bug000008
function
int shlock_tryopen
(shkey_t *key, int flags, shlock_t **lock_p)
Create a new lock on a mutex unless one has already been created.
Param
num
A positive number identifying the lock.
flags
A set of modifiers to configure the lock. (SHLK_XXX)
Note
The libshare uses negative numbers for internal locks.
Return Value
A 0 on success, a 1 when the mutex is already locked, and a -1 on error.
See
SHLOCK_SYSTEM group__libshare__memlock_1gaf99dc958d5d8980511586e0c5a41c56e member SHLK_PRIVATE group__libshare__memlock_1ga1115629744ded6de6f3c5d2c51650b7a member
function
int shlock_close
(shkey_t *key)
Unlock a mutex.
define
SHLOCK_SYSTEM
-9999
A lock used by the share library in order to ensure no two threads perform a system call at the same instance.
define
SHLK_READ_ONLY
O_RDONLY
A flag which indicates the lock applies to only 'Read' I/O access.
define
SHLK_WRITE_ONLY
O_WRONLY
A flag which indicates the lock applies to only 'Write' I/O access.
define
SHLK_IO
O_RDWR
A flag which indicates the lock applies to all I/O access.
define
SHLK_PRIVATE
O_EXCL
In memory this Prevents the mutex from allowing the same thread to access the lock.
For a file indicates only the originating process may remove lock.
Note
Similar to a semaphore as the lock is not based on thread conditions.
define
SHLK_OVERRIDE
O_TRUNC
A flag which indicates the previous lock should be over-written.
define
SHLK_NOWAIT
O_NONBLOCK
A flag which indicates to not wait for a lock to become available.
define
shlock_open_num
shlock_open(ashkey_num(_num), (_flags))
Opens a lock based on a number.
See
shlock_open() group__libshare__memlock_1ga671af607715bbe4181e78f174ea13e49 member
define
shlock_open_str
shlock_open(ashkey_str(_str), (_flags))
Opens a lock based on a string.
See
shlock_open() group__libshare__memlock_1ga671af607715bbe4181e78f174ea13e49 member
define
shlock_tryopen_num
shlock_tryopen(ashkey_num(_num), (_flags), (_keyp))
Opens a lock based on a number.
See
shlock_tryopen() group__libshare__memlock_1gaeb92477a7ff8dead2095664ab39a0578 member
define
shlock_tryopen_str
shlock_tryopen(ashkey_str(_str), (_flags), (_keyp))
Opens a lock based on a string.
See
shlock_tryopen() group__libshare__memlock_1gaeb92477a7ff8dead2095664ab39a0578 member
define
shlock_close_num
shlock_close(ashkey_num(_num), (_flags))
Closes a lock based on a number.
See
shlock_close() group__libshare__memlock_1ga837b545d13b80013d1eb6496597e01a4 member
define
shlock_close_str
shlock_close(ashkey_str(_str))
Closes a lock based on a string.
See
shlock_close() group__libshare__memlock_1ga837b545d13b80013d1eb6496597e01a4 member