summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorAdam Jackson <ajax@redhat.com>2022-03-22 18:24:29 -0400
committerAdam Jackson <ajax@redhat.com>2022-04-26 15:08:31 -0400
commitafcdb6fb0045c6186aa83d9298f327a7ec1b2cb9 (patch)
tree416328cefaba3eb1a1007800df8f5f7611fbeeb6
parent1ab48f3cc966751d86e434808180beb2dc76c4fa (diff)
downloadxorg-lib-libX11-afcdb6fb0045c6186aa83d9298f327a7ec1b2cb9.tar.gz
global: call XInitThreads() from the library's constructor
There is really no point in not being thread safe, I measured, all you can see happen is noop performance gets like twice as slow and you have thread safety bugs. And we're using xcb as the transport which means we should expect threads in our clients anyway. Just do it. This assumes your compiler understands __attribute__((constructor)). If this is not your compiler, you can disable this with the appropriate configure flag, but be aware you're asking for bugs. Signed-off-by: Adam Jackson <ajax@redhat.com>
-rw-r--r--configure.ac9
-rw-r--r--src/globals.c16
2 files changed, 16 insertions, 9 deletions
diff --git a/configure.ac b/configure.ac
index 231bcacb..641bba0b 100644
--- a/configure.ac
+++ b/configure.ac
@@ -148,6 +148,15 @@ if test x$XLIB_LOADABLE_XCURSOR = xyes; then
fi
AC_MSG_RESULT($XLIB_LOADABLE_XCURSOR)
+AC_ARG_ENABLE(thread-safety-constructor,
+ AS_HELP_STRING([--disable-thread-safety-constructor]),
+ [Controls mandatory thread safety support],
+ [USE_THREAD_SAFETY_CONSTRUCTOR=$enableval],
+ [USE_THREAD_SAFETY_CONSTRUCTOR="yes"])
+if test "x$USE_THREAD_SAFETY_CONSTRUCTOR" = "xyes"; then
+ AC_DEFINE(USE_THREAD_SAFETY_CONSTRUCTOR,1,[Call XInitThreads() from the library constructor])
+fi
+
# Checks for header files.
AC_CHECK_HEADERS([sys/filio.h sys/select.h sys/ioctl.h sys/socket.h])
diff --git a/src/globals.c b/src/globals.c
index 1aaa8c67..ea3fe6e1 100644
--- a/src/globals.c
+++ b/src/globals.c
@@ -97,12 +97,10 @@ int XTestInputActionType = 0;
int XTestFakeAckType = 1;
#endif
-/*
- * NOTE: any additional external definition NEED
- * to be inserted BELOW this point!!!
- */
-
-/*
- * NOTE: any additional external definition NEED
- * to be inserted ABOVE this point!!!
- */
+#ifdef USE_THREAD_SAFETY_CONSTRUCTOR
+__attribute__((constructor)) static void
+xlib_ctor(void)
+{
+ XInitThreads();
+}
+#endif