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.
|
| 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.
|
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.
◆ 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
-
| semaphore | The semaphore to acquire |
◆ kinc_semaphore_destroy()
| KINC_FUNC void kinc_semaphore_destroy |
( |
kinc_semaphore_t * | semaphore | ) |
|
Destroys a semaphore.
- Parameters
-
| semaphore | The semaphore to destroy |
◆ kinc_semaphore_init()
| KINC_FUNC void kinc_semaphore_init |
( |
kinc_semaphore_t * | semaphore, |
|
|
int | current, |
|
|
int | max ) |
Initializes a semaphore.
- Parameters
-
| semaphore | The semaphore to initialize |
| current | The current count of the semaphore |
| max | The 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
-
| semaphore | The semaphore to increase the count on |
| count | The 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
-
| semaphore | The semaphore to acquire |
| timeout | The timeout in seconds after which the function returns if the semaphore-count could not be decreased |
- Returns
- Whether the semaphore-count could be decreased