#pragma once #include #ifdef NAUNET_ON_WINDOWS #include "../../winwrap.h" #else #include #endif #ifdef NAUNET_HAS_THREAD_CANCEL enum { NNWT_THREAD_CANCEL_DEFERRED = PTHREAD_CANCEL_DEFERRED, NNWT_THREAD_CANCEL_ASYNCHRONOUS = PTHREAD_CANCEL_ASYNCHRONOUS }; #endif #ifdef NAUNET_ON_WINDOWS enum { NNWT_THREAD_SCHED_OTHER = 0, NNWT_THREAD_SCHED_FIFO, NNWT_THREAD_SCHED_RR }; #else enum { NNWT_THREAD_SCHED_OTHER = SCHED_OTHER, NNWT_THREAD_SCHED_FIFO = SCHED_FIFO, NNWT_THREAD_SCHED_RR = SCHED_RR }; #endif struct nn_thread { #ifdef NAUNET_ON_WINDOWS HANDLE thread; #else pthread_t thread; #endif }; struct nn_mutex { #ifdef NAUNET_ON_WINDOWS CRITICAL_SECTION mutex; #else pthread_mutex_t mutex; #endif }; 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 bool condition; }; typedef f64 nn_os_tstamp; #define NNWT_TS_FROM_USEC(usec) ((usec) * 1e-6) #ifdef NAUNET_ON_WINDOWS #define NNWT_THREADCALL __stdcall typedef unsigned long nn_thread_result; #else #define NNWT_THREADCALL 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); void nn_thread_create(struct nn_thread *thread, nn_thread_func func, void *userdata); void nn_thread_set_priority(s32 policy, s32 priority); void nn_thread_set_name(const char *name); 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 nn_thread_detach(struct nn_thread *thread); void nn_mutex_init(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); 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);