From e84da83774a981be3a325c64d887a393a83aac7b Mon Sep 17 00:00:00 2001 From: Andrew Opalach Date: Thu, 30 Oct 2025 12:29:40 -0400 Subject: Add nn_locked_assert() Signed-off-by: Andrew Opalach --- src/util/thread/thread.h | 6 ++++-- src/util/thread/thread_linux.c | 6 ++++-- src/util/thread/thread_windows.c | 6 ++++-- 3 files changed, 12 insertions(+), 6 deletions(-) (limited to 'src/util') diff --git a/src/util/thread/thread.h b/src/util/thread/thread.h index 763fdfb..766af49 100644 --- a/src/util/thread/thread.h +++ b/src/util/thread/thread.h @@ -70,6 +70,8 @@ typedef unsigned long nn_thread_result; typedef void * nn_thread_result; #endif +#define nn_locked_assert(expr, lock) al_assert(!nn_mutex_lock(lock) && (expr) && !nn_mutex_unlock(lock)) + typedef nn_thread_result (NNWT_THREADCALL * nn_thread_func)(void *); void nn_thread_sleep(nn_os_tstamp delay); @@ -87,8 +89,8 @@ void nn_thread_setcanceltype(s32 type); //void nn_thread_detach(struct nn_thread *thread); void nn_mutex_init(struct nn_mutex *mutex); -void nn_mutex_lock(struct nn_mutex *mutex); -void nn_mutex_unlock(struct nn_mutex *mutex); +s32 nn_mutex_lock(struct nn_mutex *mutex); +s32 nn_mutex_unlock(struct nn_mutex *mutex); void nn_mutex_destroy(struct nn_mutex *mutex); void nn_cond_init(struct nn_cond *cond); diff --git a/src/util/thread/thread_linux.c b/src/util/thread/thread_linux.c index a548ff8..cd80d06 100644 --- a/src/util/thread/thread_linux.c +++ b/src/util/thread/thread_linux.c @@ -62,16 +62,18 @@ void nn_mutex_init(struct nn_mutex *mutex) al_assert(ret == 0); } -void nn_mutex_lock(struct nn_mutex *mutex) +s32 nn_mutex_lock(struct nn_mutex *mutex) { s32 ret = pthread_mutex_lock(&mutex->mutex); al_assert(ret != EINVAL); + return ret; } -void nn_mutex_unlock(struct nn_mutex *mutex) +s32 nn_mutex_unlock(struct nn_mutex *mutex) { s32 ret = pthread_mutex_unlock(&mutex->mutex); al_assert(ret != EINVAL); + return ret; } void nn_mutex_destroy(struct nn_mutex *mutex) diff --git a/src/util/thread/thread_windows.c b/src/util/thread/thread_windows.c index 53337a4..3ea4d4a 100644 --- a/src/util/thread/thread_windows.c +++ b/src/util/thread/thread_windows.c @@ -76,14 +76,16 @@ void nn_mutex_init(struct nn_mutex *mutex) InitializeCriticalSection(&mutex->mutex); } -void nn_mutex_lock(struct nn_mutex *mutex) +s32 nn_mutex_lock(struct nn_mutex *mutex) { EnterCriticalSection(&mutex->mutex); + return 0; } -void nn_mutex_unlock(struct nn_mutex *mutex) +s32 nn_mutex_unlock(struct nn_mutex *mutex) { LeaveCriticalSection(&mutex->mutex); + return 0; } void nn_mutex_destroy(struct nn_mutex *mutex) -- cgit v1.2.3-101-g0448