summaryrefslogtreecommitdiff
path: root/src/util
diff options
context:
space:
mode:
authorAndrew Opalach <andrew@akon.city> 2025-10-30 12:29:40 -0400
committerAndrew Opalach <andrew@akon.city> 2025-10-30 12:29:40 -0400
commite84da83774a981be3a325c64d887a393a83aac7b (patch)
tree01f6337923fc1341de670e47bae856ef85ffa049 /src/util
parented403279224444f9fb3bac68a1ab008f8e7dfd8c (diff)
downloadlibnaunet-e84da83774a981be3a325c64d887a393a83aac7b.tar.gz
libnaunet-e84da83774a981be3a325c64d887a393a83aac7b.tar.bz2
libnaunet-e84da83774a981be3a325c64d887a393a83aac7b.zip
Add nn_locked_assert()
Signed-off-by: Andrew Opalach <andrew@akon.city>
Diffstat (limited to 'src/util')
-rw-r--r--src/util/thread/thread.h6
-rw-r--r--src/util/thread/thread_linux.c6
-rw-r--r--src/util/thread/thread_windows.c6
3 files changed, 12 insertions, 6 deletions
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)