[PATCH v3 x11proto-core 1/3] Add xthread_trylock for detecting unsafe multihreaded Xlib usage.

Rami Ylimäki rami.ylimaki at vincit.fi
Fri Feb 4 06:42:29 PST 2011


Xlib can be configured with --enable-checked-locks option to check if
it's called from multiple threads even though XInitThreads hasn't been
called first. This detection is currently implemented with
phtread_trylock.

Signed-off-by: Rami Ylimäki <rami.ylimaki at vincit.fi>
Signed-off-by: Erkki Seppälä <erkki.seppala at vincit.fi>
---
 Xthreads.h |    4 ++++
 1 files changed, 4 insertions(+), 0 deletions(-)

diff --git a/Xthreads.h b/Xthreads.h
index 3d44208..15cbb2d 100644
--- a/Xthreads.h
+++ b/Xthreads.h
@@ -230,6 +230,7 @@ typedef pthread_mutex_t xmutex_rec;
 #      define xthread_set_specific(k,v) pthread_setspecific(k,v)
 #      define xmutex_clear(m) pthread_mutex_destroy(m)
 #      define xmutex_lock(m) pthread_mutex_lock(m)
+#      define xmutex_trylock(m) pthread_mutex_trylock(m)
 #      define xmutex_unlock(m) pthread_mutex_unlock(m)
 #      ifndef XPRE_STANDARD_API
 #       define xthread_key_create(kp,d) pthread_key_create(kp,d)
@@ -290,6 +291,9 @@ typedef xmutex_rec *xmutex_t;
 # ifndef xmutex_free
 #  define xmutex_free(m) xfree((char *)m)
 # endif
+# ifndef xmutex_trylock /* generate compiler error */
+#  define xmutex_trylock(m) "xmutex_trylock not defined"()
+# endif
 # ifndef xthread_have_id
 #  define xthread_have_id(id) id
 # endif
-- 
1.6.3.3



More information about the xorg-devel mailing list