posix-next API 0.1.0
Out-of-tree Zephyr POSIX module
Loading...
Searching...
No Matches
POSIX_SEMAPHORES

POSIX Semaphores option group. More...

Files

file  semaphore.h
 POSIX semaphores API (<semaphore.h>)
 

Macros

#define SEM_FAILED   ((sem_t *) 0)
 Returned by sem_open() on failure.
 

Typedefs

typedef struct k_sem sem_t
 Semaphore object type.
 

Functions

int sem_destroy (sem_t *semaphore)
 Destroy an unnamed semaphore.
 
int sem_getvalue (sem_t *ZRESTRICT semaphore, int *ZRESTRICT value)
 Get the current value of a semaphore.
 
int sem_init (sem_t *semaphore, int pshared, unsigned int value)
 Initialise an unnamed semaphore.
 
int sem_post (sem_t *semaphore)
 Unlock a semaphore (increment its count).
 
int sem_timedwait (sem_t *ZRESTRICT semaphore, struct timespec *ZRESTRICT abstime)
 Lock a semaphore with an absolute timeout.
 
int sem_trywait (sem_t *semaphore)
 Try to lock a semaphore without blocking.
 
int sem_wait (sem_t *semaphore)
 Lock a semaphore, blocking until it becomes available.
 
sem_tsem_open (const char *name, int oflags,...)
 Open or create a named semaphore.
 
int sem_unlink (const char *name)
 Remove a named semaphore.
 
int sem_close (sem_t *sem)
 Close a named semaphore.
 

Detailed Description

POSIX Semaphores option group.

Macro Definition Documentation

◆ SEM_FAILED

#define SEM_FAILED   ((sem_t *) 0)

Returned by sem_open() on failure.

Definition at line 30 of file semaphore.h.

Typedef Documentation

◆ sem_t

typedef struct k_sem sem_t

Semaphore object type.

Definition at line 34 of file semaphore.h.

Function Documentation

◆ sem_close()

int sem_close ( sem_t sem)

Close a named semaphore.

Parameters
semSemaphore to close.
Returns
0 on success, or -1 with errno set on failure.
See also
https://pubs.opengroup.org/onlinepubs/9699919799/functions/sem_close.html

◆ sem_destroy()

int sem_destroy ( sem_t semaphore)

Destroy an unnamed semaphore.

Parameters
semaphoreSemaphore to destroy.
Returns
0 on success, or -1 with errno set on failure.
See also
https://pubs.opengroup.org/onlinepubs/9699919799/functions/sem_destroy.html

◆ sem_getvalue()

int sem_getvalue ( sem_t *ZRESTRICT  semaphore,
int *ZRESTRICT  value 
)

Get the current value of a semaphore.

Parameters
semaphoreSemaphore to query.
valueOutput: current count (implementation may report 0 if waiters are present).
Returns
0 on success, or -1 with errno set on failure.
See also
https://pubs.opengroup.org/onlinepubs/9699919799/functions/sem_getvalue.html

◆ sem_init()

int sem_init ( sem_t semaphore,
int  pshared,
unsigned int  value 
)

Initialise an unnamed semaphore.

Parameters
semaphoreSemaphore to initialise.
psharedNon-zero if the semaphore is shared between processes.
valueInitial count (must be <= SEM_VALUE_MAX).
Returns
0 on success, or -1 with errno set on failure.
See also
https://pubs.opengroup.org/onlinepubs/9699919799/functions/sem_init.html

◆ sem_open()

sem_t * sem_open ( const char *  name,
int  oflags,
  ... 
)

Open or create a named semaphore.

Parameters
nameSemaphore name (implementation-defined path).
oflagsFlags: O_CREAT, O_EXCL.
...If O_CREAT is set: mode_t mode, unsigned int value.
Returns
Pointer to the semaphore on success, or SEM_FAILED on failure.
See also
https://pubs.opengroup.org/onlinepubs/9699919799/functions/sem_open.html

◆ sem_post()

int sem_post ( sem_t semaphore)

Unlock a semaphore (increment its count).

Parameters
semaphoreSemaphore to post.
Returns
0 on success, or -1 with errno set on failure.
See also
https://pubs.opengroup.org/onlinepubs/9699919799/functions/sem_post.html

◆ sem_timedwait()

int sem_timedwait ( sem_t *ZRESTRICT  semaphore,
struct timespec *ZRESTRICT  abstime 
)

Lock a semaphore with an absolute timeout.

Parameters
semaphoreSemaphore to wait on.
abstimeAbsolute timeout (CLOCK_REALTIME).
Returns
0 on success, -1 with errno = ETIMEDOUT on timeout, or -1 with errno set on another failure.
See also
https://pubs.opengroup.org/onlinepubs/9699919799/functions/sem_timedwait.html

◆ sem_trywait()

int sem_trywait ( sem_t semaphore)

Try to lock a semaphore without blocking.

Parameters
semaphoreSemaphore to try.
Returns
0 on success, -1 with errno = EAGAIN if the count is zero, or -1 with errno set on another failure.
See also
https://pubs.opengroup.org/onlinepubs/9699919799/functions/sem_trywait.html

◆ sem_unlink()

int sem_unlink ( const char *  name)

Remove a named semaphore.

Parameters
nameSemaphore name.
Returns
0 on success, or -1 with errno set on failure.
See also
https://pubs.opengroup.org/onlinepubs/9699919799/functions/sem_unlink.html

◆ sem_wait()

int sem_wait ( sem_t semaphore)

Lock a semaphore, blocking until it becomes available.

Parameters
semaphoreSemaphore to wait on.
Returns
0 on success, or -1 with errno set on failure.
See also
https://pubs.opengroup.org/onlinepubs/9699919799/functions/sem_wait.html