xref: /xnu-10063.121.3/osfmk/man/semaphore_create.html (revision 2c2f96dc2b9a4408a43d3150ae9c105355ca3daa)
1*2c2f96dcSApple OSS Distributions<h2>semaphore_create</h2>
2*2c2f96dcSApple OSS Distributions<hr>
3*2c2f96dcSApple OSS Distributions<p>
4*2c2f96dcSApple OSS Distributions<strong>Function</strong> - Create a new semaphore.
5*2c2f96dcSApple OSS Distributions<h3>SYNOPSIS</h3>
6*2c2f96dcSApple OSS Distributions<pre>
7*2c2f96dcSApple OSS Distributions<strong>kern_return_t	semaphore_create</strong>
8*2c2f96dcSApple OSS Distributions		<strong>(task_t</strong>                   <var>task</var>,
9*2c2f96dcSApple OSS Distributions		 <strong>semaphore_t</strong>        <var>*semaphore</var>,
10*2c2f96dcSApple OSS Distributions		 <strong>int</strong>                    <var>policy</var>,
11*2c2f96dcSApple OSS Distributions		 <strong>int</strong>                     <var>value</var><strong>);</strong>
12*2c2f96dcSApple OSS Distributions</pre>
13*2c2f96dcSApple OSS Distributions<h3>PARAMETERS</h3>
14*2c2f96dcSApple OSS Distributions<dl>
15*2c2f96dcSApple OSS Distributions<dt> <var>task</var>
16*2c2f96dcSApple OSS Distributions<dd>
17*2c2f96dcSApple OSS Distributions[in task port] The task receiving the send right of the newly created semaphore.
18*2c2f96dcSApple OSS Distributions<p>
19*2c2f96dcSApple OSS Distributions<dt> <var>semaphore</var>
20*2c2f96dcSApple OSS Distributions<dd>
21*2c2f96dcSApple OSS Distributions[out send right] The port naming the created semaphore.
22*2c2f96dcSApple OSS Distributions<p>
23*2c2f96dcSApple OSS Distributions<dt> <var>policy</var>
24*2c2f96dcSApple OSS Distributions<dd>
25*2c2f96dcSApple OSS Distributions[in scalar] The blocked thread wakeup policy for the newly created semaphore. Valid policies are:
26*2c2f96dcSApple OSS Distributions<dl>
27*2c2f96dcSApple OSS Distributions<p>
28*2c2f96dcSApple OSS Distributions  <dt> SYNC_POLICY_FIFO
29*2c2f96dcSApple OSS Distributions<dd>
30*2c2f96dcSApple OSS Distributionsa first-in-first-out policy for scheduling thread wakeup.
31*2c2f96dcSApple OSS Distributions     <p>
32*2c2f96dcSApple OSS Distributions  <dt> SYNC_POLICY_FIXED_PRIORITY
33*2c2f96dcSApple OSS Distributions<dd>
34*2c2f96dcSApple OSS Distributionsa fixed priority policy for scheduling thread wakeup.
35*2c2f96dcSApple OSS Distributions     </dl>
36*2c2f96dcSApple OSS Distributions     <p>
37*2c2f96dcSApple OSS Distributions<dt> <var>value</var>
38*2c2f96dcSApple OSS Distributions<dd>
39*2c2f96dcSApple OSS Distributions[in scalar] The initial value of the semaphore count.
40*2c2f96dcSApple OSS Distributions</dl>
41*2c2f96dcSApple OSS Distributions<h3>DESCRIPTION</h3>
42*2c2f96dcSApple OSS Distributions<p>
43*2c2f96dcSApple OSS DistributionsThe <strong>semaphore_create</strong> function creates a new semaphore, associates the
44*2c2f96dcSApple OSS Distributionscreated semaphore with the specified task, and returns a send right
45*2c2f96dcSApple OSS Distributionsnaming the new semaphore.  In order to support a robust
46*2c2f96dcSApple OSS Distributionsproducer/consumer communication service, Interrupt Service Routines
47*2c2f96dcSApple OSS Distributions(ISR) must be able to signal semaphores. The semaphore synchronizer
48*2c2f96dcSApple OSS Distributionsservice is designed to allow user-level device drivers to perform
49*2c2f96dcSApple OSS Distributionssignal operations, eliminating the need for event counters.  Device
50*2c2f96dcSApple OSS Distributionsdrivers which utilize semaphores are responsible for creating (via
51*2c2f96dcSApple OSS Distributions<strong>semaphore_create</strong>) and exporting (via <strong>device_get_status</strong>)
52*2c2f96dcSApple OSS Distributionssemaphores for
53*2c2f96dcSApple OSS Distributionsuser level access. Device driver semaphore creation is done at device
54*2c2f96dcSApple OSS Distributionsinitialization time. Device drivers may support multiple semaphores.
55*2c2f96dcSApple OSS Distributions<h3>RETURN VALUES</h3>
56*2c2f96dcSApple OSS Distributions<dl>
57*2c2f96dcSApple OSS Distributions  <p>
58*2c2f96dcSApple OSS Distributions<dt> <strong>KERN_INVALID_ARGUMENT</strong>
59*2c2f96dcSApple OSS Distributions<dd>
60*2c2f96dcSApple OSS DistributionsThe task argument or the policy argument was invalid,
61*2c2f96dcSApple OSS Distributions     or the initial value of the semaphore was invalid.
62*2c2f96dcSApple OSS Distributions     <p>
63*2c2f96dcSApple OSS Distributions<dt> <strong>KERN_RESOURCE_SHORTAGE</strong>
64*2c2f96dcSApple OSS Distributions<dd>
65*2c2f96dcSApple OSS DistributionsThe kernel could not allocate the semaphore.
66*2c2f96dcSApple OSS Distributions     <p>
67*2c2f96dcSApple OSS Distributions<dt> <strong>KERN_SUCCESS</strong>
68*2c2f96dcSApple OSS Distributions<dd>
69*2c2f96dcSApple OSS DistributionsThe semaphore was successfully created.
70*2c2f96dcSApple OSS Distributions</dl>
71*2c2f96dcSApple OSS Distributions<h3>RELATED INFORMATION</h3>
72*2c2f96dcSApple OSS Distributions<p>
73*2c2f96dcSApple OSS DistributionsFunctions:
74*2c2f96dcSApple OSS Distributions<a href="semaphore_destroy.html"><strong>semaphore_destroy</strong></a>,
75*2c2f96dcSApple OSS Distributions<a href="semaphore_signal.html"><strong>semaphore_signal</strong></a>,
76*2c2f96dcSApple OSS Distributions<a href="semaphore_signal_all.html"><strong>semaphore_signal_all</strong></a>,
77*2c2f96dcSApple OSS Distributions<a href="semaphore_wait.html"><strong>semaphore_wait</strong></a>,
78*2c2f96dcSApple OSS Distributions<a href="device_get_status.html"><strong>device_get_status</strong></a>.
79