Sturk 1.0.2
Publish-subscribe C implementation.
Loading...
Searching...
No Matches
sem.h File Reference

Semaphore. More...

#include "st/bits.h"
#include <stdbool.h>
Include dependency graph for sem.h:
This graph shows which files directly or indirectly include this file:

Go to the source code of this file.

Typedefs

typedef struct StSem StSem
 Semaphore.
 

Functions

StSemst_sem_create (StBits args)
 Create a semaphore.
 
void st_sem_destroy (StSem *sem)
 Destroy a semaphore.
 
void st_sem_wait (StSem *sem)
 Wait on semaphore.
 
bool st_sem_trywait (StSem *sem)
 Decrement the semaphore counter if it is greater than 0.
 
void st_sem_post (StSem *sem)
 Increment the semaphore counter.
 

Detailed Description

Semaphore.

Function Documentation

◆ st_sem_create()

StSem * st_sem_create ( StBits  args)

Create a semaphore.

Parameters
[in]argsThe configuration arguments.
Returns
The new semaphore.

◆ st_sem_destroy()

void st_sem_destroy ( StSem sem)

Destroy a semaphore.

Parameters
[in,out]semThe semaphore.

◆ st_sem_post()

void st_sem_post ( StSem sem)

Increment the semaphore counter.

Parameters
[in,out]semThe semaphore.

◆ st_sem_trywait()

bool st_sem_trywait ( StSem sem)

Decrement the semaphore counter if it is greater than 0.

Parameters
[in,out]semThe semaphore.

Does not block the calling thread.

Returns
True, if the counter has been successfully decremented.

◆ st_sem_wait()

void st_sem_wait ( StSem sem)

Wait on semaphore.

Blocks the calling thread until the semaphore counter is 0. Decrement the counter.

Parameters
[in,out]semThe semaphore.