22#ifndef _RFB_COMMON_THREADING_H
23#define _RFB_COMMON_THREADING_H
25#include <rfb/rfbconfig.h>
27#ifdef LIBVNCSERVER_HAVE_LIBPTHREAD
30#define LOCK(mutex) (rfbLog("%s:%d LOCK(%s,0x%x)\n",__FILE__,__LINE__,#mutex,&(mutex)), pthread_mutex_lock(&(mutex)))
31#define UNLOCK(mutex) (rfbLog("%s:%d UNLOCK(%s,0x%x)\n",__FILE__,__LINE__,#mutex,&(mutex)), pthread_mutex_unlock(&(mutex)))
32#define MUTEX(mutex) pthread_mutex_t (mutex)
33#define INIT_MUTEX(mutex) (rfbLog("%s:%d INIT_MUTEX(%s,0x%x)\n",__FILE__,__LINE__,#mutex,&(mutex)), pthread_mutex_init(&(mutex),NULL))
34#define TINI_MUTEX(mutex) (rfbLog("%s:%d TINI_MUTEX(%s)\n",__FILE__,__LINE__,#mutex), pthread_mutex_destroy(&(mutex)))
35#define TSIGNAL(cond) (rfbLog("%s:%d TSIGNAL(%s)\n",__FILE__,__LINE__,#cond), pthread_cond_signal(&(cond)))
36#define WAIT(cond,mutex) (rfbLog("%s:%d WAIT(%s,%s)\n",__FILE__,__LINE__,#cond,#mutex), pthread_cond_wait(&(cond),&(mutex)))
37#define COND(cond) pthread_cond_t (cond)
38#define INIT_COND(cond) (rfbLog("%s:%d INIT_COND(%s)\n",__FILE__,__LINE__,#cond), pthread_cond_init(&(cond),NULL))
39#define TINI_COND(cond) (rfbLog("%s:%d TINI_COND(%s)\n",__FILE__,__LINE__,#cond), pthread_cond_destroy(&(cond)))
40#define IF_PTHREADS(x) x
43#define LOCK(mutex) pthread_mutex_lock(&(mutex))
44#define UNLOCK(mutex) pthread_mutex_unlock(&(mutex))
46#define MUTEX(mutex) pthread_mutex_t (mutex)
47#define MUTEX_SIZE (sizeof(pthread_mutex_t))
48#define INIT_MUTEX(mutex) pthread_mutex_init(&(mutex),NULL)
49#define TINI_MUTEX(mutex) pthread_mutex_destroy(&(mutex))
50#define TSIGNAL(cond) pthread_cond_signal(&(cond))
51#define WAIT(cond,mutex) pthread_cond_wait(&(cond),&(mutex))
52#define COND(cond) pthread_cond_t (cond)
53#define INIT_COND(cond) pthread_cond_init(&(cond),NULL)
54#define TINI_COND(cond) pthread_cond_destroy(&(cond))
55#define IF_PTHREADS(x) x
56#define THREAD_ROUTINE_RETURN_TYPE void*
57#define THREAD_ROUTINE_RETURN_VALUE NULL
58#define THREAD_SLEEP_MS(ms) usleep(ms*1000)
59#define THREAD_JOIN(thread) pthread_join(thread, NULL)
60#define THREAD_DETACH(thread) pthread_detach(thread)
61#define CURRENT_THREAD_ID pthread_self()
63#elif defined(LIBVNCSERVER_HAVE_WIN32THREADS)
65#define LOCK(mutex) EnterCriticalSection(&(mutex))
66#define UNLOCK(mutex) LeaveCriticalSection(&(mutex))
67#define MUTEX(mutex) CRITICAL_SECTION (mutex)
68#define MUTEX_SIZE (sizeof(CRITICAL_SECTION))
69#define INIT_MUTEX(mutex) InitializeCriticalSection(&(mutex))
70#define TINI_MUTEX(mutex) DeleteCriticalSection(&(mutex))
71#define TSIGNAL(cond) WakeAllConditionVariable(&(cond))
72#define WAIT(cond,mutex) SleepConditionVariableCS(&(cond),&(mutex),INFINITE);
73#define COND(cond) CONDITION_VARIABLE (cond)
74#define INIT_COND(cond) InitializeConditionVariable(&(cond));
75#define TINI_COND(cond)
77#define THREAD_ROUTINE_RETURN_TYPE void
78#define THREAD_ROUTINE_RETURN_VALUE
79#define THREAD_SLEEP_MS(ms) Sleep(ms)
80#define THREAD_JOIN(thread) WaitForSingleObject((HANDLE)thread, INFINITE)
81#define THREAD_DETACH(thread) CloseHandle((HANDLE)thread)
82#define CURRENT_THREAD_ID GetCurrentThreadId()
87#define INIT_MUTEX(mutex)
88#define TINI_MUTEX(mutex)
90#define WAIT(cond,mutex) this_is_unsupported
92#define INIT_COND(cond)
93#define TINI_COND(cond)