CardSight 0.1.0
C API reference for the CardSight firmware and application
Loading...
Searching...
No Matches
semaphore.h File Reference

Counting semaphores. More...

Go to the source code of this file.

Data Structures

struct  semaphore
 A counting semaphore. More...

Functions

void sema_init_limit (struct semaphore *sem, uint32_t initial, uint32_t limit)
 Initialize a counting semaphore.
int down_timeout (struct semaphore *sem, int timeout_ms)
 Take one count from a semaphore.
void up (struct semaphore *sem)
 Add one count to a semaphore.

Detailed Description

Counting semaphores.

down_timeout() waits at most timeout_ms milliseconds and answers -ETIMEDOUT when the count did not arrive; a negative timeout waits forever.

Function Documentation

◆ down_timeout()

int down_timeout ( struct semaphore * sem,
int timeout_ms )

Take one count from a semaphore.

Parameters
[in]semSemaphore to take from.
[in]timeout_msMilliseconds to wait; negative waits forever, 0 does not wait.
Returns
0 when a count was taken, -ETIMEDOUT when none arrived, or -EINVAL for an uninitialized semaphore.

◆ sema_init_limit()

void sema_init_limit ( struct semaphore * sem,
uint32_t initial,
uint32_t limit )

Initialize a counting semaphore.

Parameters
[out]semSemaphore structure to initialize.
[in]initialInitial count.
[in]limitMaximum count.

◆ up()

void up ( struct semaphore * sem)

Add one count to a semaphore.

Parameters
[in]semSemaphore to release.