1 <h2>semaphore_create
</h2>
<hr>
<p>
<strong>Function
</strong> - Create a new semaphore.
<h3>SYNOPSIS
</h3>
<pre>
<strong>kern_return_t semaphore_create
</strong>
<strong>(task_t
</strong> <var>task
</var>,
<strong>semaphore_t
</strong> <var>*semaphore
</var>,
<strong>int
</strong> <var>policy
</var>,
<strong>int
</strong> <var>value
</var><strong>);
</strong>
</pre>
<h3>PARAMETERS
</h3>
<dl>
<dt> <var>task
</var>
<dd>
[in task port] The task receiving the send right of the newly created semaphore.
<p>
<dt> <var>semaphore
</var>
<dd>
[out send right] The port naming the created semaphore.
<p>
<dt> <var>policy
</var>
<dd>
[in scalar] The blocked thread wakeup policy for the newly created semaphore. Valid policies are:
<dl>
<p>
<dt> SYNC_POLICY_FIFO
<dd>
a first-in-first-out policy for scheduling thread wakeup.
<p>
<dt> SYNC_POLICY_FIXED_PRIORITY
<dd>
a fixed priority policy for scheduling thread wakeup.
</dl>
<p>
<dt> <var>value
</var>
<dd>
[in scalar] The initial value of the semaphore count.
</dl>
<h3>DESCRIPTION
</h3>
<p>
The
<strong>semaphore_create
</strong> function creates a new semaphore, associates the
created semaphore with the specified task, and returns a send right
naming the new semaphore. In order to support a robust
producer/consumer communication service, Interrupt Service Routines
(ISR) must be able to signal semaphores. The semaphore synchronizer
service is designed to allow user-level device drivers to perform
signal operations, eliminating the need for event counters. Device
drivers which utilize semaphores are responsible for creating (via
<strong>semaphore_create
</strong>) and exporting (via
<strong>device_get_status
</strong>)
semaphores for
user level access. Device driver semaphore creation is done at device
initialization time. Device drivers may support multiple semaphores.
<h3>RETURN VALUES
</h3>
<dl>
<p>
<dt> <strong>KERN_INVALID_ARGUMENT
</strong>
<dd>
The task argument or the policy argument was invalid,
or the initial value of the semaphore was invalid.
<p>
<dt> <strong>KERN_RESOURCE_SHORTAGE
</strong>
<dd>
The kernel could not allocate the semaphore.
<p>
<dt> <strong>KERN_SUCCESS
</strong>
<dd>
The semaphore was successfully created.
</dl>
<h3>RELATED INFORMATION
</h3>
<p>
Functions:
<a href=
"semaphore_destroy.html"><strong>semaphore_destroy
</strong></a>,
<a href=
"semaphore_signal.html"><strong>semaphore_signal
</strong></a>,
<a href=
"semaphore_signal_all.html"><strong>semaphore_signal_all
</strong></a>,
<a href=
"semaphore_wait.html"><strong>semaphore_wait
</strong></a>,
<a href=
"device_get_status.html"><strong>device_get_status
</strong></a>.