summaryrefslogtreecommitdiff
path: root/src/util/thread
diff options
context:
space:
mode:
authorAndrew Opalach <andrew@akon.city> 2025-05-25 18:35:12 -0400
committerAndrew Opalach <andrew@akon.city> 2025-05-25 18:35:12 -0400
commit9fb3646511998310fc8c967c239803f38b2bdc5b (patch)
tree92f1bbc2c7cacfcf0c24b49f88ba220cdeebbde9 /src/util/thread
parentef86574ec5d859727695da65f683f0774a3b4460 (diff)
downloadlibnaunet-9fb3646511998310fc8c967c239803f38b2bdc5b.tar.gz
libnaunet-9fb3646511998310fc8c967c239803f38b2bdc5b.tar.bz2
libnaunet-9fb3646511998310fc8c967c239803f38b2bdc5b.zip
Windows XP support
Signed-off-by: Andrew Opalach <andrew@akon.city>
Diffstat (limited to 'src/util/thread')
-rw-r--r--src/util/thread/thread.h4
-rw-r--r--src/util/thread/thread_windows.c59
2 files changed, 63 insertions, 0 deletions
diff --git a/src/util/thread/thread.h b/src/util/thread/thread.h
index 6ea5722..142aa3c 100644
--- a/src/util/thread/thread.h
+++ b/src/util/thread/thread.h
@@ -47,7 +47,11 @@ struct nn_mutex {
struct nn_cond {
#ifdef NAUNET_ON_WINDOWS
+#ifdef NAUNET_WIN32_COMPAT_MODE
+ HANDLE event;
+#else
CONDITION_VARIABLE cond;
+#endif
#else
pthread_cond_t cond;
#endif
diff --git a/src/util/thread/thread_windows.c b/src/util/thread/thread_windows.c
index 9ce85e2..8722d0a 100644
--- a/src/util/thread/thread_windows.c
+++ b/src/util/thread/thread_windows.c
@@ -1,3 +1,5 @@
+#include <al/lib.h>
+
#include "thread.h"
NTSTATUS(__stdcall *NtDelayExecution)(BOOL Alertable, PLARGE_INTEGER DelayInterval);
@@ -42,6 +44,28 @@ void nn_thread_detach(struct nn_thread *thread)
}
*/
+/*
+void nn_mutex_init(struct nn_mutex *mutex)
+{
+ mutex->mutex = CreateMutex(NULL, FALSE, NULL);
+}
+
+void nn_mutex_lock(struct nn_mutex *mutex)
+{
+ WaitForSingleObject(mutex->mutex, INFINITE);
+}
+
+void nn_mutex_unlock(struct nn_mutex *mutex)
+{
+ ReleaseMutex(mutex->mutex);
+}
+
+void nn_mutex_destroy(struct nn_mutex *mutex)
+{
+ CloseHandle(mutex->mutex);
+}
+*/
+
void nn_mutex_init(struct nn_mutex *mutex)
{
InitializeCriticalSection(&mutex->mutex);
@@ -62,6 +86,40 @@ void nn_mutex_destroy(struct nn_mutex *mutex)
DeleteCriticalSection(&mutex->mutex);
}
+#ifdef NAUNET_WIN32_COMPAT_MODE
+void nn_cond_init(struct nn_cond *cond)
+{
+ cond->condition = true;
+ cond->event = CreateEvent(NULL, TRUE, FALSE, NULL);
+}
+
+void nn_cond_wait(struct nn_cond *cond, struct nn_mutex *mutex)
+{
+ al_assert(cond->condition);
+ cond->condition = false;
+ nn_mutex_unlock(mutex);
+ WaitForSingleObject(cond->event, INFINITE);
+ ResetEvent(cond->event);
+ nn_mutex_lock(mutex);
+}
+
+bool nn_cond_is_waiting(struct nn_cond *cond)
+{
+ return !cond->condition;
+}
+
+void nn_cond_signal(struct nn_cond *cond)
+{
+ al_assert(!cond->condition);
+ cond->condition = true;
+ SetEvent(cond->event);
+}
+
+void nn_cond_destroy(struct nn_cond *cond)
+{
+ CloseHandle(cond->event);
+}
+#else
void nn_cond_init(struct nn_cond *cond)
{
cond->condition = true;
@@ -91,3 +149,4 @@ void nn_cond_destroy(struct nn_cond *cond)
{
(void)cond;
}
+#endif