Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Continuous updates extension from TurboVNC #557

Open
wants to merge 6 commits into
base: master
Choose a base branch
from
Open
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Next Next commit
threading: recursive mutex
Volodymyr Samokhatko committed Mar 16, 2023
commit 9722d5fd2fc4814d57f69c44e942dc050f55589d
18 changes: 18 additions & 0 deletions include/rfb/threading.h
Original file line number Diff line number Diff line change
@@ -26,11 +26,20 @@

#ifdef LIBVNCSERVER_HAVE_LIBPTHREAD
#include <pthread.h>
#define RFB_THREADING_GLUE_DETAIL(x, y) x ## y
#define RFB_THREADING_GLUE(x, y) RFB_THREADING_GLUE_DETAIL(x, y)
#if 0 /* debugging */
#define LOCK(mutex) (rfbLog("%s:%d LOCK(%s,0x%x)\n",__FILE__,__LINE__,#mutex,&(mutex)), pthread_mutex_lock(&(mutex)))
#define UNLOCK(mutex) (rfbLog("%s:%d UNLOCK(%s,0x%x)\n",__FILE__,__LINE__,#mutex,&(mutex)), pthread_mutex_unlock(&(mutex)))
#define MUTEX(mutex) pthread_mutex_t (mutex)
#define INIT_MUTEX(mutex) (rfbLog("%s:%d INIT_MUTEX(%s,0x%x)\n",__FILE__,__LINE__,#mutex,&(mutex)), pthread_mutex_init(&(mutex),NULL))
#define INIT_MUTEX_RECURSIVE(mutex) do { \
rfbLog("%s:%d INIT_MUTEX_RECURSIVE(%s,0x%x)\n",__FILE__,__LINE__,#mutex,&(mutex); \
pthread_mutexattr_t RFB_THREADING_GLUE(recattr, __LINE__); \
pthread_mutexattr_settype(&RFB_THREADING_GLUE(recattr, __LINE__), PTHREAD_MUTEX_RECURSIVE); \
pthread_mutex_init(&(mutex), &RFB_THREADING_GLUE(recattr, __LINE__)); \
pthread_mutexattr_destroy(&RFB_THREADING_GLUE(recattr, __LINE__)); \
} while (0)
#define TINI_MUTEX(mutex) (rfbLog("%s:%d TINI_MUTEX(%s)\n",__FILE__,__LINE__,#mutex), pthread_mutex_destroy(&(mutex)))
#define TSIGNAL(cond) (rfbLog("%s:%d TSIGNAL(%s)\n",__FILE__,__LINE__,#cond), pthread_cond_signal(&(cond)))
#define WAIT(cond,mutex) (rfbLog("%s:%d WAIT(%s,%s)\n",__FILE__,__LINE__,#cond,#mutex), pthread_cond_wait(&(cond),&(mutex)))
@@ -46,6 +55,13 @@
#define MUTEX(mutex) pthread_mutex_t (mutex)
#define MUTEX_SIZE (sizeof(pthread_mutex_t))
#define INIT_MUTEX(mutex) pthread_mutex_init(&(mutex),NULL)
#define INIT_MUTEX_RECURSIVE(mutex) do { \
pthread_mutexattr_t RFB_THREADING_GLUE(recattr, __LINE__); \
pthread_mutexattr_init(&RFB_THREADING_GLUE(recattr, __LINE__)); \
pthread_mutexattr_settype(&RFB_THREADING_GLUE(recattr, __LINE__), PTHREAD_MUTEX_RECURSIVE); \
pthread_mutex_init(&(mutex), &RFB_THREADING_GLUE(recattr, __LINE__)); \
pthread_mutexattr_destroy(&RFB_THREADING_GLUE(recattr, __LINE__)); \
} while (0)
#define TINI_MUTEX(mutex) pthread_mutex_destroy(&(mutex))
#define TSIGNAL(cond) pthread_cond_signal(&(cond))
#define WAIT(cond,mutex) pthread_cond_wait(&(cond),&(mutex))
@@ -66,6 +82,7 @@
#define MUTEX(mutex) CRITICAL_SECTION (mutex)
#define MUTEX_SIZE (sizeof(CRITICAL_SECTION))
#define INIT_MUTEX(mutex) InitializeCriticalSection(&(mutex))
#define INIT_MUTEX_RECURSIVE(mutex) INIT_MUTEX(mutex)
#define TINI_MUTEX(mutex) DeleteCriticalSection(&(mutex))
#define TSIGNAL(cond) WakeAllConditionVariable(&(cond))
#define WAIT(cond,mutex) SleepConditionVariableCS(&(cond),&(mutex),INFINITE);
@@ -83,6 +100,7 @@
#define UNLOCK(mutex)
#define MUTEX(mutex)
#define INIT_MUTEX(mutex)
#define INIT_MUTEX_RECURSIVE(mutex)
#define TINI_MUTEX(mutex)
#define TSIGNAL(cond)
#define WAIT(cond,mutex) this_is_unsupported