Kore
Loading...
Searching...
No Matches
semaphore.h File Reference

A semaphore is a fancier version of an event that includes a counter to control how many threads are allowed to work on a task. More...

#include <kinc/global.h>
#include <kinc/backend/semaphore.h>
#include <stdbool.h>

Go to the source code of this file.

Data Structures

struct  kinc_semaphore

Typedefs

typedef struct kinc_semaphore kinc_semaphore_t

Functions

KINC_FUNC void kinc_semaphore_init (kinc_semaphore_t *semaphore, int current, int max)
 Initializes a semaphore.
KINC_FUNC void kinc_semaphore_destroy (kinc_semaphore_t *semaphore)
 Destroys a semaphore.
KINC_FUNC void kinc_semaphore_release (kinc_semaphore_t *semaphore, int count)
 Increases the current count of the semaphore, therefore allowing more acquires to succeed.
KINC_FUNC void kinc_semaphore_acquire (kinc_semaphore_t *semaphore)
 Decreases the count of the semaphore by one. Blocks until it is possible to decrease the count if it already reached zero.
KINC_FUNC bool kinc_semaphore_try_to_acquire (kinc_semaphore_t *semaphore, double timeout)
 Attempts to decrease the count of the semaphore by one.

Detailed Description

A semaphore is a fancier version of an event that includes a counter to control how many threads are allowed to work on a task.

Function Documentation

◆ kinc_semaphore_acquire()

KINC_FUNC void kinc_semaphore_acquire ( kinc_semaphore_t * semaphore)

Decreases the count of the semaphore by one. Blocks until it is possible to decrease the count if it already reached zero.

Parameters
semaphoreThe semaphore to acquire

◆ kinc_semaphore_destroy()

KINC_FUNC void kinc_semaphore_destroy ( kinc_semaphore_t * semaphore)

Destroys a semaphore.

Parameters
semaphoreThe semaphore to destroy

◆ kinc_semaphore_init()

KINC_FUNC void kinc_semaphore_init ( kinc_semaphore_t * semaphore,
int current,
int max )

Initializes a semaphore.

Parameters
semaphoreThe semaphore to initialize
currentThe current count of the semaphore
maxThe maximum allowed count of the semaphore

◆ kinc_semaphore_release()

KINC_FUNC void kinc_semaphore_release ( kinc_semaphore_t * semaphore,
int count )

Increases the current count of the semaphore, therefore allowing more acquires to succeed.

Parameters
semaphoreThe semaphore to increase the count on
countThe amount by which the count will be increased

◆ kinc_semaphore_try_to_acquire()

KINC_FUNC bool kinc_semaphore_try_to_acquire ( kinc_semaphore_t * semaphore,
double timeout )

Attempts to decrease the count of the semaphore by one.

Parameters
semaphoreThe semaphore to acquire
timeoutThe timeout in seconds after which the function returns if the semaphore-count could not be decreased
Returns
Whether the semaphore-count could be decreased