Amazon FreeRTOS: POSIX
Return to main page ↑
semaphore.h File Reference

Semaphores. More...

#include "FreeRTOS_POSIX/time.h"
#include "FreeRTOS_POSIX_types.h"

Go to the source code of this file.

Typedefs

typedef PosixSemType_t sem_t
 Semaphore type.
 

Functions

int sem_destroy (sem_t *sem)
 Destroy an unnamed semaphore. More...
 
int sem_getvalue (sem_t *sem, int *sval)
 Get the value of a semaphore. More...
 
int sem_init (sem_t *sem, int pshared, unsigned value)
 Initialize an unnamed semaphore. More...
 
int sem_post (sem_t *sem)
 Unlock a semaphore. More...
 
int sem_timedwait (sem_t *sem, const struct timespec *abstime)
 Lock a semaphore with timeout. More...
 
int sem_trywait (sem_t *sem)
 Lock a semaphore if available. More...
 
int sem_wait (sem_t *sem)
 Lock a semaphore. More...
 

Detailed Description

Function Documentation

◆ sem_destroy()

int sem_destroy ( sem_t sem)

Destroy an unnamed semaphore.

See also
http://pubs.opengroup.org/onlinepubs/9699919799/functions/sem_destroy.html
Return values
0- upon successful completion
Note
Semaphore is destroyed regardless of whether there is any thread currently blocked on this semaphore.

◆ sem_getvalue()

int sem_getvalue ( sem_t sem,
int *  sval 
)

Get the value of a semaphore.

See also
http://pubs.opengroup.org/onlinepubs/9699919799/functions/sem_getvalue.html
Return values
0- Upon successful completion
Note
If sem is locked, then the object to which sval points is set to zero.

◆ sem_init()

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

Initialize an unnamed semaphore.

See also
http://pubs.opengroup.org/onlinepubs/9699919799/functions/sem_init.html
Note
pshared is ignored. Semaphores will always be considered "shared".
Return values
0- upon successful completion
-1- otherwise. System error variable errno is also set in this case.
Side Effects Possible errno values

EINVAL - The value argument exceeds {SEM_VALUE_MAX}.
ENOSPC - A resource required to initialize the semaphore has been exhausted.

◆ sem_post()

int sem_post ( sem_t sem)

Unlock a semaphore.

See also
http://pubs.opengroup.org/onlinepubs/9699919799/functions/sem_post.html
Return values
0- upon successful completion

◆ sem_timedwait()

int sem_timedwait ( sem_t sem,
const struct timespec abstime 
)

Lock a semaphore with timeout.

See also
http://pubs.opengroup.org/onlinepubs/9699919799/functions/sem_timedwait.html
Return values
0- upon successful completion
-1- otherwise. System error variable errno is also set in this case.
Side Effects Possible errno values

EINVAL - parameter specified a nanoseconds field value less than zero or greater than or equal to 1000 million
ETIMEDOUT - The semaphore could not be locked before the specified timeout expired.
Note
Deadlock detection is not implemented.

◆ sem_trywait()

int sem_trywait ( sem_t sem)

Lock a semaphore if available.

See also
http://pubs.opengroup.org/onlinepubs/9699919799/functions/sem_trywait.html
Return values
0- upon successful completion
-1- otherwise. System error variable errno is also set in this case.
Side Effects Possible errno values

EAGAIN - The semaphore was already locked, so it cannot be immediately locked by the sem_trywait() operation.

◆ sem_wait()

int sem_wait ( sem_t sem)

Lock a semaphore.

See also
http://pubs.opengroup.org/onlinepubs/9699919799/functions/sem_wait.html
Return values
0- upon successful completion
-1- otherwise. System error variable errno is also set in this case.
Note
Deadlock detection is not implemented.