#pragma once #include #include #include /*! \file mutex.h \brief Provides mutexes which are used to synchronize threads and uber-mutexes which are used to synchronize processes. */ #ifdef __cplusplus extern "C" { #endif typedef struct kinc_mutex { kinc_mutex_impl_t impl; } kinc_mutex_t; /// /// Initializes a mutex-object. /// /// The mutex to initialize KINC_FUNC void kinc_mutex_init(kinc_mutex_t *mutex); /// /// Destroys a mutex-object. /// /// The mutex to destroy KINC_FUNC void kinc_mutex_destroy(kinc_mutex_t *mutex); /// /// Locks a mutex. A mutex can only be locked from one thread - when other threads attempt to lock the mutex the function will only return once the mutex has /// been unlocked. /// /// The mutex to lock KINC_FUNC void kinc_mutex_lock(kinc_mutex_t *mutex); /// /// Attempts to lock the mutex which will only succeed if no other thread currently holds the lock. /// /// The mutex to lock /// Whether the mutex could be locked KINC_FUNC bool kinc_mutex_try_to_lock(kinc_mutex_t *mutex); /// /// Unlocks the mutex which then allows other threads to lock it. /// /// The mutex to unlock KINC_FUNC void kinc_mutex_unlock(kinc_mutex_t *mutex); typedef struct kinc_uber_mutex { kinc_uber_mutex_impl_t impl; } kinc_uber_mutex_t; /// /// Initializes an uber-mutex-object. /// /// The uber-mutex to initialize /// A name assigned to the uber-mutex - uber-mutex-creation fails if an uber-mutex of that name already exists /// Whether the uber-mutex could be created KINC_FUNC bool kinc_uber_mutex_init(kinc_uber_mutex_t *mutex, const char *name); /// /// Destroys an uber-mutex-obejct. /// /// The uber-mutex to destroy KINC_FUNC void kinc_uber_mutex_destroy(kinc_uber_mutex_t *mutex); /// /// Locks an uber-mutex. /// /// The uber-mutex to lock KINC_FUNC void kinc_uber_mutex_lock(kinc_uber_mutex_t *mutex); /// /// Unlocks an uber-mutex. /// /// The uber-mutex to unlock /// KINC_FUNC void kinc_uber_mutex_unlock(kinc_uber_mutex_t *mutex); #ifdef __cplusplus } #endif