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

Provides mutexes which are used to synchronize threads and uber-mutexes which are used to synchronize processes. More...

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

Go to the source code of this file.

Data Structures

struct  kinc_mutex
struct  kinc_uber_mutex

Typedefs

typedef struct kinc_mutex kinc_mutex_t
typedef struct kinc_uber_mutex kinc_uber_mutex_t

Functions

KINC_FUNC void kinc_mutex_init (kinc_mutex_t *mutex)
 Initializes a mutex-object.
KINC_FUNC void kinc_mutex_destroy (kinc_mutex_t *mutex)
 Destroys a mutex-object.
KINC_FUNC void kinc_mutex_lock (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.
KINC_FUNC bool kinc_mutex_try_to_lock (kinc_mutex_t *mutex)
 Attempts to lock the mutex which will only succeed if no other thread currently holds the lock.
KINC_FUNC void kinc_mutex_unlock (kinc_mutex_t *mutex)
 Unlocks the mutex which then allows other threads to lock it.
KINC_FUNC bool kinc_uber_mutex_init (kinc_uber_mutex_t *mutex, const char *name)
 Initializes an uber-mutex-object.
KINC_FUNC void kinc_uber_mutex_destroy (kinc_uber_mutex_t *mutex)
 Destroys an uber-mutex-obejct.
KINC_FUNC void kinc_uber_mutex_lock (kinc_uber_mutex_t *mutex)
 Locks an uber-mutex.
KINC_FUNC void kinc_uber_mutex_unlock (kinc_uber_mutex_t *mutex)
 Unlocks an uber-mutex.

Detailed Description

Provides mutexes which are used to synchronize threads and uber-mutexes which are used to synchronize processes.

Function Documentation

◆ kinc_mutex_destroy()

KINC_FUNC void kinc_mutex_destroy ( kinc_mutex_t * mutex)

Destroys a mutex-object.

Parameters
mutexThe mutex to destroy

◆ kinc_mutex_init()

KINC_FUNC void kinc_mutex_init ( kinc_mutex_t * mutex)

Initializes a mutex-object.

Parameters
mutexThe mutex to initialize

◆ kinc_mutex_lock()

KINC_FUNC void kinc_mutex_lock ( 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.

Parameters
mutexThe mutex to lock

◆ kinc_mutex_try_to_lock()

KINC_FUNC bool kinc_mutex_try_to_lock ( kinc_mutex_t * mutex)

Attempts to lock the mutex which will only succeed if no other thread currently holds the lock.

Parameters
mutexThe mutex to lock
Returns
Whether the mutex could be locked

◆ kinc_mutex_unlock()

KINC_FUNC void kinc_mutex_unlock ( kinc_mutex_t * mutex)

Unlocks the mutex which then allows other threads to lock it.

Parameters
mutexThe mutex to unlock

◆ kinc_uber_mutex_destroy()

KINC_FUNC void kinc_uber_mutex_destroy ( kinc_uber_mutex_t * mutex)

Destroys an uber-mutex-obejct.

Parameters
mutexThe uber-mutex to destroy

◆ kinc_uber_mutex_init()

KINC_FUNC bool kinc_uber_mutex_init ( kinc_uber_mutex_t * mutex,
const char * name )

Initializes an uber-mutex-object.

Parameters
mutexThe uber-mutex to initialize
nameA name assigned to the uber-mutex - uber-mutex-creation fails if an uber-mutex of that name already exists
Returns
Whether the uber-mutex could be created

◆ kinc_uber_mutex_lock()

KINC_FUNC void kinc_uber_mutex_lock ( kinc_uber_mutex_t * mutex)

Locks an uber-mutex.

Parameters
mutexThe uber-mutex to lock

◆ kinc_uber_mutex_unlock()

KINC_FUNC void kinc_uber_mutex_unlock ( kinc_uber_mutex_t * mutex)

Unlocks an uber-mutex.

Parameters
mutexThe uber-mutex to unlock
Returns