class Semaphore
Defined at line 33 of file ../../zircon/kernel/include/kernel/semaphore.h
A basic counting semaphore used to control access to a shared resource.
Think of Semaphore as a gatekeeper that allows a certain number of threads to
pass through a gate so they can access some resource.
Threads queue up at the gate by calling Wait and then block until the
gatekeeper lets them through or they give up and leave the queue because of
timeout or thread signal. In the case of timeout or thread signal, the
waiter may not proceed to the resource.
Calling Post tells the gatekeeper that they may immediately admit one through
the gate (if there's a waiter in the queue) or admit one in the future once a
waiter has queued up.
Public Methods
void Post (OwnedWaitQueue * queue_to_own)
Unblocks a single thread if any are waiting. If none are waiting, this
operation logically increments the count such that a future call to |Wait|
may return without blocking.
|Post| has release memory order semantics and synchronizes with |Wait|.
|queue_to_own| is the OwnedWaitQueue that the unblocked thread will take
ownership of. If this is not-null, then we will perform an assign-owner
operation on the queue. If there is no thread waiting, then no
assign-owner operation will occur.
Defined at line 25 of file ../../zircon/kernel/kernel/semaphore.cc
void Semaphore (int64_t initial_count)
Defined at line 35 of file ../../zircon/kernel/include/kernel/semaphore.h
void Semaphore (const Semaphore & )
Defined at line 37 of file ../../zircon/kernel/include/kernel/semaphore.h
void Semaphore (Semaphore && )
Defined at line 38 of file ../../zircon/kernel/include/kernel/semaphore.h
Semaphore & operator= (const Semaphore & )
Defined at line 39 of file ../../zircon/kernel/include/kernel/semaphore.h
void ~Semaphore ()
Defined at line 40 of file ../../zircon/kernel/include/kernel/semaphore.h
zx_status_t Wait ()
If the count is positive, decrement the count and return ZX_OK. Otherwise,
decrement the count and wait (uninterruptibly) until some other thread
wakes us via |Post|.
|Wait| has acquire memory order semantics and synchronizes with |Post|.
Defined at line 59 of file ../../zircon/kernel/include/kernel/semaphore.h
zx_status_t Wait (const Deadline & deadline)
Just like Wait(), but interruptible. In addition to ZX_OK, the return
value can be ZX_ERR_TIMED_OUT if the deadline had passed or one of the
ZX_ERR_INTERNAL_INTR errors if the thread had a signal delivered.
|Wait| has acquire memory order semantics and synchronizes with |Post|.
Defined at line 68 of file ../../zircon/kernel/include/kernel/semaphore.h
int64_t count ()
Observe the current internal count of the semaphore.
This should only be used for testing/diagnostic purposes.
Defined at line 75 of file ../../zircon/kernel/include/kernel/semaphore.h
uint64_t num_waiters ()
Observe the current internal count of waiters.
This should only be used for testing/diagnostic purposes.
Defined at line 80 of file ../../zircon/kernel/include/kernel/semaphore.h