summaryrefslogtreecommitdiff
path: root/thread.h
diff options
context:
space:
mode:
authorNicholas Clark <nick@ccl4.org>2022-01-04 18:27:17 +0000
committerNicholas Clark <nick@ccl4.org>2022-01-12 20:12:50 +0000
commitc4b6855dd57cd9a2ac4647c33c5636ed7d15d64a (patch)
tree03836a092e02ec90439d106e93ea40179629cacb /thread.h
parent79314061206e91d12ed1d2ee0915c80b7375f8b8 (diff)
downloadperl-c4b6855dd57cd9a2ac4647c33c5636ed7d15d64a.tar.gz
For C++ extensions, use the pthreads definition of PERL_GET_CONTEXT
Configure probes the C compiler to find out whether it supports C11 thread local storage, and if found uses this for PERL_SET_CONTEXT/PERL_GET_CONTEXT, in preference to the pthread_setspecific()/pthread_getspecific() approach. However, we can come unstuck with XS extensions written in C++, as C++ and C disagree on the syntax used for thread local storage, meaning that the working token that Configure probed for C turns out to be a compiler error on C++. As Configure doesn't have a way to probe for C++ dialects, we just take the safe option and do the same as 5.34.0 and earlier - use pthreads on C++. This commit is minimal because the implementation of PERL_SET_CONTEXT for C11 thread local storage was already defensively written to *also* call pthread_setspecific().
Diffstat (limited to 'thread.h')
-rw-r--r--thread.h12
1 files changed, 10 insertions, 2 deletions
diff --git a/thread.h b/thread.h
index 744d6425df..cfa3287b5c 100644
--- a/thread.h
+++ b/thread.h
@@ -372,8 +372,16 @@
# define PTHREAD_GETSPECIFIC(key) pthread_getspecific(key)
#endif
-#if defined(PERL_THREAD_LOCAL) && !defined(PERL_GET_CONTEXT) && !defined(PERL_SET_CONTEXT)
-/* Use C11 thread-local storage, where possible: */
+#if defined(PERL_THREAD_LOCAL) && !defined(PERL_GET_CONTEXT) && !defined(PERL_SET_CONTEXT) && !defined(__cplusplus)
+/* Use C11 thread-local storage, where possible.
+ * Frustratingly we can't use it for C++ extensions, C++ and C disagree on the
+ * syntax used for thread local storage, meaning that the working token that
+ * Configure probed for C turns out to be a compiler error on C++. Great.
+ * (Well, unless one or both is supporting non-standard syntax as an extension)
+ * As Configure doesn't have a way to probe for C++ dialects, we just take the
+ * safe option and do the same as 5.34.0 and earlier - use pthreads on C++.
+ * Of course, if C++ XS extensions really want to avoid *all* this overhead,
+ * they should #define PERL_NO_GET_CONTEXT and pass aTHX/aTHX_ explicitly) */
# define PERL_USE_THREAD_LOCAL
extern PERL_THREAD_LOCAL void *PL_current_context;