mirror of
https://github.com/python/cpython.git
synced 2025-07-07 19:35:27 +00:00
gh-81057: Move Threading-Related Globals to _PyRuntimeState (#100084)
https://github.com/python/cpython/issues/81057
This commit is contained in:
parent
bc8cdf8c3d
commit
1160001b34
11 changed files with 114 additions and 54 deletions
|
@ -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();
|
||||
}
|
||||
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue