summaryrefslogtreecommitdiff
path: root/src/util/thread
diff options
context:
space:
mode:
authorAndrew Opalach <andrew@akon.city> 2024-12-24 14:38:53 -0500
committerAndrew Opalach <andrew@akon.city> 2024-12-24 14:38:53 -0500
commit822e754cafdc5a32c80c97ca015cd6f9008329c3 (patch)
treeaa8831eca4f896928e9c3ba78446ca95762fccac /src/util/thread
parentdcc43df0a40cbb2126505396cac4db26008d49b1 (diff)
downloadlibnaunet-822e754cafdc5a32c80c97ca015cd6f9008329c3.tar.gz
libnaunet-822e754cafdc5a32c80c97ca015cd6f9008329c3.tar.bz2
libnaunet-822e754cafdc5a32c80c97ca015cd6f9008329c3.zip
Rename, cleanup and pass on readability
Signed-off-by: Andrew Opalach <andrew@akon.city>
Diffstat (limited to 'src/util/thread')
-rw-r--r--src/util/thread/thread.h58
-rw-r--r--src/util/thread/thread_linux.c35
-rw-r--r--src/util/thread/thread_windows.c35
3 files changed, 63 insertions, 65 deletions
diff --git a/src/util/thread/thread.h b/src/util/thread/thread.h
index 5975c84..921de23 100644
--- a/src/util/thread/thread.h
+++ b/src/util/thread/thread.h
@@ -8,14 +8,14 @@
#include "../../winwrap.h"
#endif
-#ifdef AKIYO_HAS_THREAD_CANCEL
+#ifdef NAUNET_HAS_THREAD_CANCEL
enum {
- AKI_THREAD_CANCEL_DEFERRED = PTHREAD_CANCEL_DEFERRED,
- AKI_THREAD_CANCEL_ASYNCHRONOUS = PTHREAD_CANCEL_ASYNCHRONOUS
+ NNWT_THREAD_CANCEL_DEFERRED = PTHREAD_CANCEL_DEFERRED,
+ NNWT_THREAD_CANCEL_ASYNCHRONOUS = PTHREAD_CANCEL_ASYNCHRONOUS
};
#endif
-struct aki_thread {
+struct nn_thread {
#ifndef _WIN32
pthread_t thread;
#else
@@ -23,7 +23,7 @@ struct aki_thread {
#endif
};
-struct aki_mutex {
+struct nn_mutex {
#ifndef _WIN32
pthread_mutex_t mutex;
#else
@@ -31,7 +31,7 @@ struct aki_mutex {
#endif
};
-struct aki_cond {
+struct nn_cond {
#ifndef _WIN32
pthread_cond_t cond;
#else
@@ -40,37 +40,37 @@ struct aki_cond {
bool condition;
};
-typedef f64 aki_os_tstamp;
+typedef f64 nn_os_tstamp;
-#define AKI_TS_FROM_USEC(usec) ((usec) * 1e-6)
+#define NNWT_TS_FROM_USEC(usec) ((usec) * 1e-6)
#ifndef _WIN32
-#define AKI_THREADCALL
-typedef void * aki_thread_result;
+#define NNWT_THREADCALL
+typedef void * nn_thread_result;
#else
-#define AKI_THREADCALL __stdcall
-typedef unsigned long aki_thread_result;
+#define NNWT_THREADCALL __stdcall
+typedef unsigned long nn_thread_result;
#endif
-typedef aki_thread_result (AKI_THREADCALL * aki_thread_func)(void *);
+typedef nn_thread_result (NNWT_THREADCALL * nn_thread_func)(void *);
-void aki_thread_sleep(aki_os_tstamp delay);
+void nn_thread_sleep(nn_os_tstamp delay);
-void aki_thread_create(struct aki_thread *thread, aki_thread_func func, void *userdata);
-void aki_thread_join(struct aki_thread *thread);
-#ifdef AKIYO_HAS_THREAD_CANCEL
-void aki_thread_cancel(struct aki_thread *thread);
-void aki_thread_setcanceltype(s32 type);
+void nn_thread_create(struct nn_thread *thread, nn_thread_func func, void *userdata);
+void nn_thread_join(struct nn_thread *thread);
+#ifdef NAUNET_HAS_THREAD_CANCEL
+void nn_thread_cancel(struct nn_thread *thread);
+void nn_thread_setcanceltype(s32 type);
#endif
-//void aki_thread_detach(struct aki_thread *thread);
+//void nn_thread_detach(struct nn_thread *thread);
-void aki_mutex_init(struct aki_mutex *mutex);
-void aki_mutex_lock(struct aki_mutex *mutex);
-void aki_mutex_unlock(struct aki_mutex *mutex);
-void aki_mutex_destroy(struct aki_mutex *mutex);
+void nn_mutex_init(struct nn_mutex *mutex);
+void nn_mutex_lock(struct nn_mutex *mutex);
+void nn_mutex_unlock(struct nn_mutex *mutex);
+void nn_mutex_destroy(struct nn_mutex *mutex);
-void aki_cond_init(struct aki_cond *cond);
-void aki_cond_wait(struct aki_cond *cond, struct aki_mutex *mutex);
-bool aki_cond_is_waiting(struct aki_cond *cond);
-void aki_cond_signal(struct aki_cond *cond);
-void aki_cond_destroy(struct aki_cond *cond);
+void nn_cond_init(struct nn_cond *cond);
+void nn_cond_wait(struct nn_cond *cond, struct nn_mutex *mutex);
+bool nn_cond_is_waiting(struct nn_cond *cond);
+void nn_cond_signal(struct nn_cond *cond);
+void nn_cond_destroy(struct nn_cond *cond);
diff --git a/src/util/thread/thread_linux.c b/src/util/thread/thread_linux.c
index 26c3e18..bb5bcbc 100644
--- a/src/util/thread/thread_linux.c
+++ b/src/util/thread/thread_linux.c
@@ -4,7 +4,7 @@
#include "thread.h"
-void aki_thread_sleep(aki_os_tstamp delay)
+void nn_thread_sleep(nn_os_tstamp delay)
{
struct timespec tv;
tv.tv_sec = (s64)delay;
@@ -12,81 +12,80 @@ void aki_thread_sleep(aki_os_tstamp delay)
while (nanosleep(&tv, &tv) == -1 && errno == EINTR) {}
}
-void aki_thread_create(struct aki_thread *thread, aki_thread_func func, void *userdata)
+void nn_thread_create(struct nn_thread *thread, nn_thread_func func, void *userdata)
{
pthread_create(&thread->thread, NULL, func, userdata);
}
-void aki_thread_join(struct aki_thread *thread)
+void nn_thread_join(struct nn_thread *thread)
{
pthread_join(thread->thread, NULL);
}
-#ifdef AKIYO_HAS_THREAD_CANCEL
-void aki_thread_cancel(struct aki_thread *thread)
+#ifdef NAUNET_HAS_THREAD_CANCEL
+void nn_thread_cancel(struct nn_thread *thread)
{
pthread_cancel(thread->thread);
}
-void aki_thread_setcanceltype(s32 type)
+void nn_thread_setcanceltype(s32 type)
{
pthread_setcanceltype(type, NULL);
}
#endif
/*
-void aki_thread_detach(struct aki_thread *thread)
+void nn_thread_detach(struct nn_thread *thread)
{
pthread_detach(thread->thread);
}
*/
-void aki_mutex_init(struct aki_mutex *mutex)
+void nn_mutex_init(struct nn_mutex *mutex)
{
pthread_mutex_init(&mutex->mutex, NULL);
}
-void aki_mutex_lock(struct aki_mutex *mutex)
+void nn_mutex_lock(struct nn_mutex *mutex)
{
pthread_mutex_lock(&mutex->mutex);
}
-void aki_mutex_unlock(struct aki_mutex *mutex)
+void nn_mutex_unlock(struct nn_mutex *mutex)
{
pthread_mutex_unlock(&mutex->mutex);
}
-void aki_mutex_destroy(struct aki_mutex *mutex)
+void nn_mutex_destroy(struct nn_mutex *mutex)
{
pthread_mutex_destroy(&mutex->mutex);
}
-void aki_cond_init(struct aki_cond *cond)
+void nn_cond_init(struct nn_cond *cond)
{
cond->condition = true;
pthread_cond_init(&cond->cond, NULL);
}
-void aki_cond_wait(struct aki_cond *cond, struct aki_mutex *mutex)
+void nn_cond_wait(struct nn_cond *cond, struct nn_mutex *mutex)
{
cond->condition = false;
- while (!cond->condition) {
+ while (!cond->condition)
pthread_cond_wait(&cond->cond, &mutex->mutex);
- }
}
-bool aki_cond_is_waiting(struct aki_cond *cond)
+bool nn_cond_is_waiting(struct nn_cond *cond)
{
return !cond->condition;
}
-void aki_cond_signal(struct aki_cond *cond)
+void nn_cond_signal(struct nn_cond *cond)
{
cond->condition = true;
pthread_cond_signal(&cond->cond);
}
-void aki_cond_destroy(struct aki_cond *cond)
+void nn_cond_destroy(struct nn_cond *cond)
{
pthread_cond_destroy(&cond->cond);
}
diff --git a/src/util/thread/thread_windows.c b/src/util/thread/thread_windows.c
index c7fdd62..ded3b6c 100644
--- a/src/util/thread/thread_windows.c
+++ b/src/util/thread/thread_windows.c
@@ -2,86 +2,85 @@
NTSTATUS(__stdcall *NtDelayExecution)(BOOL Alertable, PLARGE_INTEGER DelayInterval);
-void aki_thread_sleep(aki_os_tstamp delay)
+void nn_thread_sleep(nn_os_tstamp delay)
{
NtDelayExecution(false, &((LARGE_INTEGER){ .QuadPart = -(s64)(delay * 1e7L) }));
}
-void aki_thread_create(struct aki_thread *thread, aki_thread_func func, void *userdata)
+void nn_thread_create(struct nn_thread *thread, nn_thread_func func, void *userdata)
{
thread->thread = CreateThread(NULL, 0, func, userdata, 0, NULL);
}
-void aki_thread_join(struct aki_thread *thread)
+void nn_thread_join(struct nn_thread *thread)
{
WaitForSingleObject(thread->thread, INFINITE);
CloseHandle(thread->thread);
}
-#ifdef AKIYO_HAS_THREAD_CANCEL
-void aki_thread_cancel(struct aki_thread *thread)
+#ifdef NAUNET_HAS_THREAD_CANCEL
+void nn_thread_cancel(struct nn_thread *thread)
{
(void)thread;
}
-void aki_thread_setcanceltype(s32 type)
+void nn_thread_setcanceltype(s32 type)
{
(void)type;
}
#endif
/*
-void aki_thread_detach(struct aki_thread *thread)
+void nn_thread_detach(struct nn_thread *thread)
{
}
*/
-void aki_mutex_init(struct aki_mutex *mutex)
+void nn_mutex_init(struct nn_mutex *mutex)
{
InitializeCriticalSection(&mutex->mutex);
}
-void aki_mutex_lock(struct aki_mutex *mutex)
+void nn_mutex_lock(struct nn_mutex *mutex)
{
EnterCriticalSection(&mutex->mutex);
}
-void aki_mutex_unlock(struct aki_mutex *mutex)
+void nn_mutex_unlock(struct nn_mutex *mutex)
{
LeaveCriticalSection(&mutex->mutex);
}
-void aki_mutex_destroy(struct aki_mutex *mutex)
+void nn_mutex_destroy(struct nn_mutex *mutex)
{
DeleteCriticalSection(&mutex->mutex);
}
-void aki_cond_init(struct aki_cond *cond)
+void nn_cond_init(struct nn_cond *cond)
{
cond->condition = true;
InitializeConditionVariable(&cond->cond);
}
-void aki_cond_wait(struct aki_cond *cond, struct aki_mutex *mutex)
+void nn_cond_wait(struct nn_cond *cond, struct nn_mutex *mutex)
{
cond->condition = false;
- while (!cond->condition) {
+ while (!cond->condition)
SleepConditionVariableCS(&cond->cond, &mutex->mutex, INFINITE);
- }
}
-bool aki_cond_is_waiting(struct aki_cond *cond)
+bool nn_cond_is_waiting(struct nn_cond *cond)
{
return !cond->condition;
}
-void aki_cond_signal(struct aki_cond *cond)
+void nn_cond_signal(struct nn_cond *cond)
{
cond->condition = true;
WakeConditionVariable(&cond->cond);
}
-void aki_cond_destroy(struct aki_cond *cond)
+void nn_cond_destroy(struct nn_cond *cond)
{
(void)cond;
}