| 1 |
@node Locks (mutexes) |
| 2 |
@subsection Locks (mutexes) |
| 3 |
|
| 4 |
Locks are used to synchronize access to the shared data. Lock may be |
| 5 |
owned only by a single thread at any given time. Recursive locks may be |
| 6 |
re-acquired by the same thread multiple times (and non-recursive locks |
| 7 |
can't). |
| 8 |
|
| 9 |
@node Locks dictionary |
| 10 |
@subsection Locks dictionary |
| 11 |
|
| 12 |
|
| 13 |
@cppdef ecl_make_lock |
| 14 |
|
| 15 |
@deftypefun cl_object ecl_make_lock (cl_object name, bool recursive) |
| 16 |
C/C++ equivalent of @coderef{mp:make-lock} without @var{key} arguments. |
| 17 |
|
| 18 |
See @coderef{mp:make-lock}. |
| 19 |
@end deftypefun |
| 20 |
|
| 21 |
|
| 22 |
@lspdef mp:make-lock |
| 23 |
|
| 24 |
@defun mp:make-lock &key name (recursive nil) |
| 25 |
Creates a lock named @var{name}. If @var{recursive} is true, a recursive |
| 26 |
lock is created that can be locked multiple times by the same thread. |
| 27 |
@end defun |
| 28 |
|
| 29 |
|
| 30 |
@cppdef mp_recursive_lock_p |
| 31 |
@lspdef mp:recursive-lock-p |
| 32 |
|
| 33 |
@deftypefun cl_object mp_recursive_lock_p (cl_object lock) |
| 34 |
@end deftypefun |
| 35 |
|
| 36 |
@defun mp:recursive-lock-p lock |
| 37 |
Predicate verifying if @var{lock} is recursive. |
| 38 |
@end defun |
| 39 |
|
| 40 |
|
| 41 |
@cppdef mp_holding_lock_p |
| 42 |
@lspdef mp:holding-lock-p |
| 43 |
|
| 44 |
@deftypefun cl_object mp_holding_lock_p (cl_object lock) |
| 45 |
@end deftypefun |
| 46 |
|
| 47 |
@defun mp:holding-lock-p lock |
| 48 |
Predicate verifying if the current thread holds @var{lock}. |
| 49 |
@end defun |
| 50 |
|
| 51 |
|
| 52 |
@cppdef mp_lock_name |
| 53 |
@lspdef mp:lock-name |
| 54 |
|
| 55 |
@deftypefun cl_object mp_lock_name (cl_object lock) |
| 56 |
@end deftypefun |
| 57 |
|
| 58 |
@defun mp:lock_name lock |
| 59 |
Returns the name of @var{lock}. |
| 60 |
@end defun |
| 61 |
|
| 62 |
|
| 63 |
@lspdef mp_lock_owner |
| 64 |
@lspdef mp:lock-owner |
| 65 |
|
| 66 |
@deftypefun cl_object mp_lock_owner (cl_object lock) |
| 67 |
@end deftypefun |
| 68 |
|
| 69 |
@defun mp:lock-owner lock |
| 70 |
Returns the process owning @var{lock} or @code{nil} if the mutex is not |
| 71 |
owned by any process. For testing whether the current thread |
| 72 |
is holding a lock see @coderef{mp:holding-lock-p}. |
| 73 |
@end defun |
| 74 |
|
| 75 |
|
| 76 |
@cppdef mp_lock_count |
| 77 |
@lspdef mp:lock-count |
| 78 |
|
| 79 |
@deftypefun cl_object mp_lock_count (cl_object lock) |
| 80 |
@end deftypefun |
| 81 |
|
| 82 |
@defun mp:lock-count lock |
| 83 |
Returns number of times @var{lock} has been locked. |
| 84 |
@end defun |
| 85 |
|
| 86 |
|
| 87 |
@cppdef mp_get_lock_wait |
| 88 |
@cppdef mp_get_lock_nowait |
| 89 |
@lspdef mp:get-lock |
| 90 |
|
| 91 |
@deftypefun cl_object mp_get_lock_wait (cl_object lock) |
| 92 |
Grabs a lock (blocking if @var{lock} is already taken). Returns |
| 93 |
@code{ECL_T}. |
| 94 |
@end deftypefun |
| 95 |
|
| 96 |
@deftypefun cl_object mp_get_lock_nowait |
| 97 |
Grabs a lock if free (non-blocking). If @var{lock} is already taken |
| 98 |
returns @code{ECL_NIL}, otherwise @code{ECL_T}. |
| 99 |
@end deftypefun |
| 100 |
|
| 101 |
@defun mp:get-lock lock &optional (wait t) |
| 102 |
Tries to acquire a lock. @var{wait} indicates whether function should |
| 103 |
block or give up if @var{lock} is already taken. If @var{wait} is |
| 104 |
@code{nil}, immediately return, if @var{wait} is a real number |
| 105 |
@var{wait} specifies a timeout in seconds and otherwise block until the |
| 106 |
lock becomes available. If @var{lock} can't be acquired return |
| 107 |
@code{nil}. Successful operation returns @code{t}. Will signal an error |
| 108 |
if the mutex is non-recursive and current thread already owns the lock. |
| 109 |
@end defun |
| 110 |
|
| 111 |
|
| 112 |
@cppdef mp_giveup_lock |
| 113 |
@lspdef mp:giveup-lock |
| 114 |
|
| 115 |
@deftypefun cl_object mp_giveup_lock (cl_object lock) |
| 116 |
@end deftypefun |
| 117 |
|
| 118 |
@defun mp:giveup-lock lock |
| 119 |
Releases @var{lock} and returns @code{t}. May signal an error if the |
| 120 |
lock is not owned by the current thread. |
| 121 |
@end defun |
| 122 |
|
| 123 |
|
| 124 |
@lspdef mp:with-lock |
| 125 |
|
| 126 |
@defmac mp:with-lock (lock-form) &body body |
| 127 |
Acquire lock for the dynamic scope of @var{body}, which is executed with |
| 128 |
the lock held by current thread. Returns the values of |
| 129 |
body. |
| 130 |
|
| 131 |
@c (lock-form &key wait-p timeout) |
| 132 |
|
| 133 |
@c If wait-p is true (the default), and the mutex is not immediately |
| 134 |
@c available, sleep until it is available. |
| 135 |
|
| 136 |
@c If timeout is given, it specifies a relative timeout, in seconds, on how |
| 137 |
@c long the system should try to acquire the lock in the contested case. |
| 138 |
|
| 139 |
@c If the mutex isn’t acquired successfully due to either wait-p or |
| 140 |
@c timeout, the body is not executed, and with-mutex returns nil. |
| 141 |
@end defmac |