| 1 |
@node Semaphores |
| 2 |
@subsection Semaphores |
| 3 |
|
| 4 |
@cindex Semaphores (synchronization) |
| 5 |
|
| 6 |
Semaphores are objects which allow an arbitrary resource |
| 7 |
count. Semaphores are used for shared access to resources where number |
| 8 |
of concurrent threads allowed to access it is limited. |
| 9 |
|
| 10 |
@node Semaphores dictionary |
| 11 |
@subsection Semaphores dictionary |
| 12 |
|
| 13 |
|
| 14 |
@cppdef ecl_make_semaphore |
| 15 |
@deftypefun cl_object ecl_make_semaphore (cl_object name, cl_fixnum count) |
| 16 |
C/C++ equivalent of @coderef{mp:make-semaphore} without @code{key} |
| 17 |
arguments. |
| 18 |
|
| 19 |
See @coderef{mp:make-semaphore}. |
| 20 |
@end deftypefun |
| 21 |
|
| 22 |
|
| 23 |
@cppdef mp_make_semaphore |
| 24 |
@lspdef mp:make-semaphore |
| 25 |
|
| 26 |
@defun mp:make-semaphore &key name count |
| 27 |
Creates a counting semaphore @var{name} with a resource count |
| 28 |
@var{count}. |
| 29 |
@end defun |
| 30 |
|
| 31 |
|
| 32 |
@cppdef mp_semaphore_name |
| 33 |
@lspdef mp:semaphore-name |
| 34 |
|
| 35 |
@deftypefun cl_object mp_semaphore_name (cl_object semaphore) |
| 36 |
@end deftypefun |
| 37 |
|
| 38 |
@defun mp:semaphore-name semaphore |
| 39 |
Returns the name of @var{semaphore}. |
| 40 |
@end defun |
| 41 |
|
| 42 |
|
| 43 |
@cppdef mp_semaphore_count |
| 44 |
@lspdef mp:semaphore-count |
| 45 |
|
| 46 |
@deftypefun cl_object mp_semaphore_count (cl_object semaphore) |
| 47 |
@end deftypefun |
| 48 |
|
| 49 |
@defun mp:semaphore-count semaphore |
| 50 |
Returns the resource count of @var{semaphore}. |
| 51 |
@end defun |
| 52 |
|
| 53 |
|
| 54 |
@cppdef mp_semaphore_wait_count |
| 55 |
@lspdef mp:semaphore-wait-count |
| 56 |
|
| 57 |
@deftypefun cl_object mp_semaphore_wait_count (cl_object semaphore) |
| 58 |
@end deftypefun |
| 59 |
|
| 60 |
@defun mp:semaphore-wait-count semaphore |
| 61 |
Returns the number of threads waiting on @var{semaphore}. |
| 62 |
@end defun |
| 63 |
|
| 64 |
|
| 65 |
@cppdef mp_semaphore_wait |
| 66 |
@lspdef mp:semaphore-wait |
| 67 |
|
| 68 |
@deftypefun cl_object mp_sempahore_wait(cl_object semaphore, cl_object count, cl_object timeout) |
| 69 |
@end deftypefun |
| 70 |
|
| 71 |
@defun mp:semaphore-wait semaphore count timeout |
| 72 |
Decrement the count of @var{semaphore} by @var{count} if the count |
| 73 |
would not be negative. |
| 74 |
|
| 75 |
Else blocks until the semaphore can be decremented. Returns the old |
| 76 |
count of @var{semaphore} on success. |
| 77 |
|
| 78 |
If timeout is not @code{nil}, it is the maximum number of seconds to |
| 79 |
wait. If the count cannot be decremented in that time, returns |
| 80 |
@code{nil} without decrementing the count. |
| 81 |
@end defun |
| 82 |
|
| 83 |
|
| 84 |
@cppdef mp_wait_on_semaphore |
| 85 |
@lspdef mp:wait-on-semaphore |
| 86 |
|
| 87 |
@deftypefun cl_object mp_wait_on_semaphore (cl_narg n, cl_object sem, ...) |
| 88 |
@end deftypefun |
| 89 |
|
| 90 |
@defun mp:wait-on-semaphore semaphore &key count timeout |
| 91 |
Waits on semaphore until it can grab @var{count} resources. |
| 92 |
|
| 93 |
Returns resource count before semaphore was acquired. |
| 94 |
|
| 95 |
This function is equivalent to @code{(mp:semaphore-wait semaphore count timeout)} |
| 96 |
@end defun |
| 97 |
|
| 98 |
|
| 99 |
@cppdef mp_try_get_semaphore |
| 100 |
@lspdef mp:try-get-semaphore |
| 101 |
|
| 102 |
@deftypefun cl_object mp_try_get_semaphore (cl_narg n, cl_object sem, ...) |
| 103 |
@end deftypefun |
| 104 |
|
| 105 |
@defun mp:try-get-semaphore semaphore &optional count |
| 106 |
Tries to get a semaphore (non-blocking). |
| 107 |
|
| 108 |
If there is no enough resource returns @code{nil}, otherwise returns |
| 109 |
resource count before semaphore was acquired. |
| 110 |
|
| 111 |
This function is equivalent to @code{(mp:semaphore-wait semaphore count 0)} |
| 112 |
@end defun |
| 113 |
|
| 114 |
|
| 115 |
@cppdef mp_signal_semaphore |
| 116 |
@lspdef mp:signal-semaphore |
| 117 |
|
| 118 |
@deftypefun cl_object mp_signal_semaphore (cl_narg n, cl_object sem, ...); |
| 119 |
@end deftypefun |
| 120 |
|
| 121 |
@defun mp:signal-semaphore semaphore &optional (count 1) |
| 122 |
Releases @var{count} units of a resource on @var{semaphore}. Returns no |
| 123 |
values. |
| 124 |
@end defun |