summaryrefslogtreecommitdiff
path: root/Python/thread_pthread.h
diff options
context:
space:
mode:
authorEric Snow <ericsnowcurrently@gmail.com>2022-12-08 17:50:58 -0700
committerGitHub <noreply@github.com>2022-12-08 17:50:58 -0700
commit1160001b34615066b1188d5fb457131b1ebb928d (patch)
tree827671c00c80bf761675700128457d7171ec8f46 /Python/thread_pthread.h
parentbc8cdf8c3d58f5d28c9e70c72eaae52c6d13f961 (diff)
downloadcpython-git-1160001b34615066b1188d5fb457131b1ebb928d.tar.gz
gh-81057: Move Threading-Related Globals to _PyRuntimeState (#100084)
https://github.com/python/cpython/issues/81057
Diffstat (limited to 'Python/thread_pthread.h')
-rw-r--r--Python/thread_pthread.h24
1 files changed, 13 insertions, 11 deletions
diff --git a/Python/thread_pthread.h b/Python/thread_pthread.h
index 1c5b320813..ae312e987b 100644
--- a/Python/thread_pthread.h
+++ b/Python/thread_pthread.h
@@ -119,20 +119,16 @@
* pthread_cond support
*/
-#if defined(HAVE_PTHREAD_CONDATTR_SETCLOCK) && defined(HAVE_CLOCK_GETTIME) && defined(CLOCK_MONOTONIC)
-// monotonic is supported statically. It doesn't mean it works on runtime.
-#define CONDATTR_MONOTONIC
-#endif
-
-// NULL when pthread_condattr_setclock(CLOCK_MONOTONIC) is not supported.
-static pthread_condattr_t *condattr_monotonic = NULL;
+#define condattr_monotonic _PyRuntime.threads._condattr_monotonic.ptr
static void
init_condattr(void)
{
#ifdef CONDATTR_MONOTONIC
- static pthread_condattr_t ca;
+# define ca _PyRuntime.threads._condattr_monotonic.val
+ // XXX We need to check the return code?
pthread_condattr_init(&ca);
+ // XXX We need to run pthread_condattr_destroy() during runtime fini.
if (pthread_condattr_setclock(&ca, CLOCK_MONOTONIC) == 0) {
condattr_monotonic = &ca; // Use monotonic clock
}
@@ -192,15 +188,21 @@ typedef struct {
"%s: %s\n", name, strerror(status)); error = 1; }
/*
- * Initialization.
+ * Initialization for the current runtime.
*/
static void
PyThread__init_thread(void)
{
+ // The library is only initialized once in the process,
+ // regardless of how many times the Python runtime is initialized.
+ static int lib_initialized = 0;
+ if (!lib_initialized) {
+ lib_initialized = 1;
#if defined(_AIX) && defined(__GNUC__)
- extern void pthread_init(void);
- pthread_init();
+ extern void pthread_init(void);
+ pthread_init();
#endif
+ }
init_condattr();
}