@node Semaphores
@subsection Semaphores

Semaphores are objects which allow an arbitrary resource
count. Semaphores are used for shared access to resources where number
of concurrent threads allowed to access it is limited.

@node Semaphores dictionary
@subsection Semaphores dictionary


@cppindex ecl_make_semaphore
@deftypefun cl_object ecl_make_semaphore (cl_object name, cl_fixnum count)
C/C++ equivalent of @code{mp:make-sempahore} without @code{key}
arguments.

See @code{mp:make-sempahore}.
@end deftypefun


@cppindex mp_make_semaphore
@lspindex mp:make-semaphore

@defun mp:make-semaphore &key name count
Creates a counting semaphore @code{name} with a resource count
@code{count}.
@end defun


@cppindex mp_semaphore_name
@lspindex mp:semaphore-name

@deftypefun cl_object mp_semaphore_name (cl_object semaphore)
@end deftypefun

@defun mp:semaphore-name semaphore
Returns @code{semaphore} name.
@end defun


@cppindex mp_semaphore_count
@lspindex mp:semaphore-count

@deftypefun cl_object mp_semaphore_count (cl_object semaphore)
@end deftypefun

@defun mp:semaphore-count semaphore
Returns @code{semaphore} count of resources.
@end defun


@cppindex mp_semaphore_wait_count
@lspindex mp:semaphore-wait-count

@deftypefun cl_object mp_semaphore_wait_count (cl_object semaphore)
@end deftypefun

@defun mp:semaphore-wait-count semaphore
Returns number of threads waiting on @code{semaphore}.
@end defun


@cppindex mp_wait_on_semaphore
@lspindex mp:wait-on-semaphore

@deftypefun cl_object mp_wait_on_semaphore (cl_object semaphore)
@end deftypefun

@defun mp:wait-on-semaphore semaphore
Waits on semaphore until it can grab the resource (blocking). Returns
resource count before semaphore was acquired.
@end defun


@cppindex mp_try_get_semaphore
@lspindex mp:try-get-semaphore

@deftypefun cl_object mp_try_get_semaphore (cl_object semaphore)
@end deftypefun

@defun mp:try-get-semaphore semaphore
Tries to get a semaphore (non-blocking). If there is no resource left
returns @code{nil}, otherwise returns resource count before semaphore
was acquired.
@end defun


@lspindex mp_signal_semaphore
@lspindex mp:signal-semaphore

@deftypefun cl_object mp_signal_semaphore (cl_narg n, cl_object sem, ...);
@end deftypefun

@defun mp:signal-semaphore semaphore &optional (count 1)
Releases @code{count} units of a resource on @code{semaphore}.
@end defun
