Motr  M0
Dijkstra semaphore

Data Structures

struct  m0_semaphore
 

Functions

M0_INTERNAL int m0_semaphore_init (struct m0_semaphore *semaphore, unsigned value)
 
M0_INTERNAL void m0_semaphore_fini (struct m0_semaphore *semaphore)
 
M0_INTERNAL void m0_semaphore_down (struct m0_semaphore *semaphore)
 
M0_INTERNAL bool m0_semaphore_trydown (struct m0_semaphore *semaphore)
 
M0_INTERNAL void m0_semaphore_up (struct m0_semaphore *semaphore)
 
M0_INTERNAL unsigned m0_semaphore_value (struct m0_semaphore *semaphore)
 
M0_INTERNAL bool m0_semaphore_timeddown (struct m0_semaphore *semaphore, const m0_time_t abs_timeout)
 
M0_INTERNAL void m0_semaphore_drain (struct m0_semaphore *semaphore)
 

Detailed Description

See also
http://en.wikipedia.org/wiki/Semaphore_(programming)

Implementation of m0_semaphore on top of Linux struct semaphore.

Linux kernel semaphore.

Implementation of m0_semaphore on top of sem_t.

User space semaphore.

Function Documentation

◆ m0_semaphore_down()

M0_INTERNAL void m0_semaphore_down ( struct m0_semaphore semaphore)

Downs the semaphore (P-operation).

Definition at line 49 of file semaphore.c.

◆ m0_semaphore_drain()

M0_INTERNAL void m0_semaphore_drain ( struct m0_semaphore semaphore)

Brings down the semaphore to 0.

Definition at line 25 of file semaphore.c.

Here is the call graph for this function:
Here is the caller graph for this function:

◆ m0_semaphore_fini()

M0_INTERNAL void m0_semaphore_fini ( struct m0_semaphore semaphore)

Definition at line 45 of file semaphore.c.

◆ m0_semaphore_init()

M0_INTERNAL int m0_semaphore_init ( struct m0_semaphore semaphore,
unsigned  value 
)

Definition at line 38 of file semaphore.c.

◆ m0_semaphore_timeddown()

M0_INTERNAL bool m0_semaphore_timeddown ( struct m0_semaphore semaphore,
const m0_time_t  abs_timeout 
)

Downs the semaphore, blocking for not longer than the (absolute) timeout given.

Note
this call with cause the thread to wait on semaphore in non-interruptable state: signals won't preempt it. Use it to wait for events that are expected to arrive in a "short time".
Parameters
abs_timeoutabsolute time since Epoch (00:00:00, 1 January 1970)
Returns
true if P-operation succeed immediately or before timeout;
false otherwise.

Definition at line 75 of file semaphore.c.

Here is the call graph for this function:
Here is the caller graph for this function:

◆ m0_semaphore_trydown()

M0_INTERNAL bool m0_semaphore_trydown ( struct m0_semaphore semaphore)

Tries to down a semaphore without blocking.

Returns true iff the P-operation succeeded without blocking.

Definition at line 60 of file semaphore.c.

Here is the caller graph for this function:

◆ m0_semaphore_up()

M0_INTERNAL void m0_semaphore_up ( struct m0_semaphore semaphore)

Ups the semaphore (V-operation).

Definition at line 65 of file semaphore.c.

◆ m0_semaphore_value()

M0_INTERNAL unsigned m0_semaphore_value ( struct m0_semaphore semaphore)

Returns the number of times a P-operation could be executed without blocking.

Note
the return value might, generally, be invalid by the time m0_semaphore_value() returns.
that the parameter is not const. This is because of POSIX sem_getvalue() prototype.

Definition at line 70 of file semaphore.c.

Here is the caller graph for this function: