Skip to content
Merged
Show file tree
Hide file tree
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Prev Previous commit
Next Next commit
Move init_condattr():ca to _PyRuntimeState.
  • Loading branch information
ericsnowcurrently committed Dec 9, 2022
commit 9d7feb7baa5d771b6ce182a6f74e5481e707c7a5
24 changes: 20 additions & 4 deletions Include/internal/pycore_pythread.h
Original file line number Diff line number Diff line change
Expand Up @@ -36,14 +36,30 @@ extern "C" {

#endif /* _POSIX_THREADS */

#if defined(_POSIX_THREADS) && !defined(HAVE_PTHREAD_STUBS)
# define _USE_PTHREADS
#endif

#if defined(_USE_PTHREADS) && 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


struct _pythread_runtime_state {
int initialized;
#if defined(_POSIX_THREADS) && !defined(HAVE_PTHREAD_STUBS)
#ifdef _USE_PTHREADS
// This matches when thread_pthread.h is used.
/* NULL when pthread_condattr_setclock(CLOCK_MONOTONIC) is not supported. */
pthread_condattr_t *condattr_monotonic;
#endif
struct {
/* NULL when pthread_condattr_setclock(CLOCK_MONOTONIC) is not supported. */
pthread_condattr_t *ptr;
# ifdef CONDATTR_MONOTONIC
/* The value to which condattr_monotonic is set. */
pthread_condattr_t val;
# endif
} _condattr_monotonic;

#endif // USE_PTHREADS
};


Expand Down
2 changes: 1 addition & 1 deletion Python/thread.c
Original file line number Diff line number Diff line change
Expand Up @@ -34,7 +34,7 @@ PyThread_init_thread(void)
#if defined(HAVE_PTHREAD_STUBS)
# define PYTHREAD_NAME "pthread-stubs"
# include "thread_pthread_stubs.h"
#elif defined(_POSIX_THREADS)
#elif defined(_USE_PTHREADS) /* AKA _PTHREADS */
# if defined(__EMSCRIPTEN__) && !defined(__EMSCRIPTEN_PTHREADS__)
# define PYTHREAD_NAME "pthread-stubs"
# else
Expand Down
11 changes: 4 additions & 7 deletions Python/thread_pthread.h
Original file line number Diff line number Diff line change
Expand Up @@ -119,19 +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

#define condattr_monotonic _PyRuntime.threads.condattr_monotonic
#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
}
Expand Down
2 changes: 0 additions & 2 deletions Tools/c-analyzer/cpython/ignored.tsv
Original file line number Diff line number Diff line change
Expand Up @@ -24,8 +24,6 @@ Modules/posixmodule.c os_dup2_impl dup3_works -

## guards around resource init
Python/thread_pthread.h PyThread__init_thread lib_initialized -
# static buffer used during one-time initialization
Python/thread_pthread.h init_condattr ca -

##-----------------------
## other values (not Python-specific)
Expand Down