#pragma once #include #include #include /*! \file semaphore.h \brief 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. */ #ifdef __cplusplus extern "C" { #endif typedef struct kinc_semaphore { kinc_semaphore_impl_t impl; } kinc_semaphore_t; /// /// Initializes a semaphore. /// /// The semaphore to initialize /// The current count of the semaphore /// The maximum allowed count of the semaphore KINC_FUNC void kinc_semaphore_init(kinc_semaphore_t *semaphore, int current, int max); /// /// Destroys a semaphore. /// /// The semaphore to destroy KINC_FUNC void kinc_semaphore_destroy(kinc_semaphore_t *semaphore); /// /// Increases the current count of the semaphore, therefore allowing more acquires to succeed. /// /// The semaphore to increase the count on /// The amount by which the count will be increased KINC_FUNC void kinc_semaphore_release(kinc_semaphore_t *semaphore, int count); /// /// Decreases the count of the semaphore by one. Blocks until it is possible to decrease the count if it already reached zero. /// /// The semaphore to acquire KINC_FUNC void kinc_semaphore_acquire(kinc_semaphore_t *semaphore); /// /// Attempts to decrease the count of the semaphore by one. /// /// The semaphore to acquire /// The timeout in seconds after which the function returns if the semaphore-count could not be decreased /// Whether the semaphore-count could be decreased KINC_FUNC bool kinc_semaphore_try_to_acquire(kinc_semaphore_t *semaphore, double timeout); #ifdef __cplusplus } #endif