Files
dusk/src/dusk/thread/threadmutex.h
T
2026-04-20 15:43:18 -05:00

73 lines
1.7 KiB
C

/**
* Copyright (c) 2025 Dominic Masters
*
* This software is released under the MIT License.
* https://opensource.org/licenses/MIT
*/
#pragma once
#include "dusk.h"
#ifdef DUSK_THREAD_PTHREAD
#include <pthread.h>
#else
#error "At least one threading implementation must be defined."
#endif
typedef struct threadlock_t {
#ifdef DUSK_THREAD_PTHREAD
pthread_mutex_t mutex;
pthread_cond_t cond;
#endif
} threadmutex_t;
/**
* Initializes a thread mutex.
*
* @param lock Pointer to the thread mutex structure to initialize.
*/
void threadMutexInit(threadmutex_t *lock);
/**
* Locks the thread mutex.
*
* @param lock Pointer to the thread mutex structure to lock.
*/
void threadMutexLock(threadmutex_t *lock);
/**
* Attempts to lock the thread mutex without blocking.
*
* @param lock Pointer to the thread mutex structure to try locking.
* @return true if the lock was acquired, false otherwise.
*/
bool_t threadMutexTryLock(threadmutex_t *lock);
/**
* Unlocks the thread mutex.
*
* @param lock Pointer to the thread mutex structure to unlock.
*/
void threadMutexUnlock(threadmutex_t *lock);
/**
* Releases the thread mutex and waits for it to be locked again.
*
* @param lock Pointer to the thread mutex structure to wait on.
*/
void threadMutexWaitLock(threadmutex_t *lock);
/**
* Signals the thread mutex, allowing a waiting thread to proceed as soon as
* this mutex is unlocked.
*
* @param lock Pointer to the thread mutex structure to signal.
*/
void threadMutexSignal(threadmutex_t *lock);
/**
* Disposes of the thread mutex.
*
* @param lock Pointer to the thread mutex structure to dispose.
*/
void threadMutexDispose(threadmutex_t *lock);