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 CURRENT_THREAD_ID pthread_self()
62 #elif defined(LIBVNCSERVER_HAVE_WIN32THREADS)
64 #define LOCK(mutex) EnterCriticalSection(&(mutex))
65 #define UNLOCK(mutex) LeaveCriticalSection(&(mutex))
66 #define MUTEX(mutex) CRITICAL_SECTION (mutex)
67 #define MUTEX_SIZE (sizeof(CRITICAL_SECTION))
68 #define INIT_MUTEX(mutex) InitializeCriticalSection(&(mutex))
69 #define TINI_MUTEX(mutex) DeleteCriticalSection(&(mutex))
70 #define TSIGNAL(cond) WakeAllConditionVariable(&(cond))
71 #define WAIT(cond,mutex) SleepConditionVariableCS(&(cond),&(mutex),INFINITE);
72 #define COND(cond) CONDITION_VARIABLE (cond)
73 #define INIT_COND(cond) InitializeConditionVariable(&(cond));
74 #define TINI_COND(cond)
75 #define IF_PTHREADS(x)
76 #define THREAD_ROUTINE_RETURN_TYPE void
77 #define THREAD_ROUTINE_RETURN_VALUE
78 #define THREAD_SLEEP_MS(ms) Sleep(ms)
79 #define THREAD_JOIN(thread) WaitForSingleObject((HANDLE)thread, INFINITE)
80 #define CURRENT_THREAD_ID GetCurrentThreadId()
85 #define INIT_MUTEX(mutex)
86 #define TINI_MUTEX(mutex)
88 #define WAIT(cond,mutex) this_is_unsupported
90 #define INIT_COND(cond)
91 #define TINI_COND(cond)
92 #define IF_PTHREADS(x)