Functions
mk_atomic_addfunction
int mk_atomic_add(mk_atomic_int_t *atomic, int value)
Add to an atomic integer.
| Parameter | Type | Description |
|---|
atomic | mk_atomic_int_t * | Atomic integer |
value | int | Value to add |
Returns Previous value (before addition)
mk_atomic_casfunction
bool mk_atomic_cas(mk_atomic_int_t *atomic, int expected, int desired)
Compare and swap an atomic integer.
If current value equals expected, sets to desired and returns true.
| Parameter | Type | Description |
|---|
atomic | mk_atomic_int_t * | Atomic integer |
expected | int | Expected current value |
desired | int | New value if expected matches |
Returns true if swap occurred, false otherwise
mk_atomic_decfunction
int mk_atomic_dec(mk_atomic_int_t *atomic)
Decrement an atomic integer.
| Parameter | Type | Description |
|---|
atomic | mk_atomic_int_t * | Atomic integer |
Returns Previous value (before decrement)
mk_atomic_getfunction
int mk_atomic_get(mk_atomic_int_t *atomic)
Get the value of an atomic integer.
| Parameter | Type | Description |
|---|
atomic | mk_atomic_int_t * | Atomic integer to read |
Returns Current value
mk_atomic_incfunction
int mk_atomic_inc(mk_atomic_int_t *atomic)
Increment an atomic integer.
| Parameter | Type | Description |
|---|
atomic | mk_atomic_int_t * | Atomic integer |
Returns Previous value (before increment)
mk_atomic_initfunction
void mk_atomic_init(mk_atomic_int_t *atomic, int value)
Initialize an atomic integer.
Must be called before any other atomic operations.
| Parameter | Type | Description |
|---|
atomic | mk_atomic_int_t * | Atomic integer to initialize |
value | int | Initial value |
mk_atomic_setfunction
int mk_atomic_set(mk_atomic_int_t *atomic, int value)
Set the value of an atomic integer.
| Parameter | Type | Description |
|---|
atomic | mk_atomic_int_t * | Atomic integer to set |
value | int | New value |
Returns Previous value
mk_mutex_createfunction
mk_mutex_t mk_mutex_create(void)
Create a mutex.
Returns Mutex handle or MK_MUTEX_INVALID on failure
mk_mutex_destroyfunction
void mk_mutex_destroy(mk_mutex_t mutex)
Destroy a mutex.
The mutex must not be locked when destroyed.
| Parameter | Type | Description |
|---|
mutex | mk_mutex_t | Mutex to destroy |
mk_mutex_lockfunction
void mk_mutex_lock(mk_mutex_t mutex)
Lock a mutex.
Blocks if the mutex is already locked by another thread.
| Parameter | Type | Description |
|---|
mutex | mk_mutex_t | Mutex to lock |
mk_mutex_try_lockfunction
bool mk_mutex_try_lock(mk_mutex_t mutex)
Try to lock a mutex without blocking.
| Parameter | Type | Description |
|---|
mutex | mk_mutex_t | Mutex to try to lock |
Returns true if lock was acquired, false if already locked
mk_mutex_unlockfunction
void mk_mutex_unlock(mk_mutex_t mutex)
Unlock a mutex.
Must be called from the same thread that locked it.
| Parameter | Type | Description |
|---|
mutex | mk_mutex_t | Mutex to unlock |
mk_semaphore_createfunction
mk_semaphore_t mk_semaphore_create(int initial_value)
Create a semaphore.
| Parameter | Type | Description |
|---|
initial_value | int | Initial semaphore count (typically 0) |
Returns Semaphore handle or MK_SEMAPHORE_INVALID on failure
mk_semaphore_destroyfunction
void mk_semaphore_destroy(mk_semaphore_t sem)
Destroy a semaphore.
| Parameter | Type | Description |
|---|
sem | mk_semaphore_t | Semaphore to destroy |
mk_semaphore_signalfunction
void mk_semaphore_signal(mk_semaphore_t sem)
Signal a semaphore (increment).
Wakes up one waiting thread if any.
| Parameter | Type | Description |
|---|
sem | mk_semaphore_t | Semaphore to signal |
mk_semaphore_try_waitfunction
bool mk_semaphore_try_wait(mk_semaphore_t sem)
Try to wait on a semaphore without blocking.
| Parameter | Type | Description |
|---|
sem | mk_semaphore_t | Semaphore to try to wait on |
Returns true if semaphore was decremented, false if count was zero
mk_semaphore_waitfunction
void mk_semaphore_wait(mk_semaphore_t sem)
Wait on a semaphore (decrement).
Blocks if the count is zero until another thread signals.
| Parameter | Type | Description |
|---|
sem | mk_semaphore_t | Semaphore to wait on |
mk_semaphore_wait_timeoutfunction
bool mk_semaphore_wait_timeout(mk_semaphore_t sem, uint32_t timeout_ms)
Wait on a semaphore with timeout.
| Parameter | Type | Description |
|---|
sem | mk_semaphore_t | Semaphore to wait on |
timeout_ms | uint32_t | Maximum time to wait in milliseconds |
Returns true if semaphore was decremented, false on timeout
mk_thread_createfunction
mk_thread_t mk_thread_create(mk_thread_func_t func, const char *name, void *user_data)
Create and start a new thread.
| Parameter | Type | Description |
|---|
func | mk_thread_func_t | Thread function to execute |
name | const char * | Thread name (for debugging, can be NULL) |
user_data | void * | User data passed to thread function |
Returns Thread handle or MK_THREAD_INVALID on failure
mk_thread_current_idfunction
uint64_t mk_thread_current_id(void)
Get the current thread's ID.
Useful for debugging and identifying threads.
Returns Current thread ID
mk_thread_destroyfunction
void mk_thread_destroy(mk_thread_t thread)
Destroy a thread handle.
The thread must have been joined first (or detached).
| Parameter | Type | Description |
|---|
thread | mk_thread_t | Thread to destroy |
mk_thread_joinfunction
int mk_thread_join(mk_thread_t thread)
Wait for a thread to finish execution.
Blocks until the thread exits.
| Parameter | Type | Description |
|---|
thread | mk_thread_t | Thread to wait for |
Returns Thread exit code, or -1 if thread is invalid
mk_thread_sleepfunction
void mk_thread_sleep(uint32_t milliseconds)
Sleep the current thread.
| Parameter | Type | Description |
|---|
milliseconds | uint32_t | Time to sleep in milliseconds |
mk_thread_supportedfunction
bool mk_thread_supported(void)
Check if threading is supported on this platform.
Returns false on Web/Emscripten where only single-threaded operation is possible.
Returns true if threading primitives are available
mk_thread_yieldfunction
void mk_thread_yield(void)
Yield execution to other threads.
Hints to the scheduler that this thread can give up its time slice.