diff options
| author | Luke Gruber <luke.gruber@shopify.com> | 2025-10-07 10:28:37 -0400 |
|---|---|---|
| committer | John Hawthorn <john@hawthorn.email> | 2025-10-07 13:00:16 -0700 |
| commit | 446257c84b92c63d84282eadca32b56ed1281a3d (patch) | |
| tree | bc9c31f92f3270c36a99f686d738d74ac6cf5e7d /thread_pthread.c | |
| parent | 7089a4e2d83a3cb1bc394c4ce3638cbc777f4cb9 (diff) | |
Add debug #define to call sched_yield before each pthread_mutex_lock
This is useful for debugging mutex issues as it increases contention for locks.
It is off by default.
Diffstat (limited to 'thread_pthread.c')
| -rw-r--r-- | thread_pthread.c | 16 |
1 files changed, 10 insertions, 6 deletions
diff --git a/thread_pthread.c b/thread_pthread.c index 5150a6173e..323659b649 100644 --- a/thread_pthread.c +++ b/thread_pthread.c @@ -90,9 +90,16 @@ static const void *const condattr_monotonic = NULL; #endif #endif +#ifdef HAVE_SCHED_YIELD +#define native_thread_yield() (void)sched_yield() +#else +#define native_thread_yield() ((void)0) +#endif + // native thread wrappers #define NATIVE_MUTEX_LOCK_DEBUG 0 +#define NATIVE_MUTEX_LOCK_DEBUG_YIELD 0 static void mutex_debug(const char *msg, void *lock) @@ -111,6 +118,9 @@ void rb_native_mutex_lock(pthread_mutex_t *lock) { int r; +#if NATIVE_MUTEX_LOCK_DEBUG_YIELD + native_thread_yield(); +#endif mutex_debug("lock", lock); if ((r = pthread_mutex_lock(lock)) != 0) { rb_bug_errno("pthread_mutex_lock", r); @@ -310,12 +320,6 @@ static rb_serial_t current_fork_gen = 1; /* We can't use GET_VM()->fork_gen */ static void threadptr_trap_interrupt(rb_thread_t *); -#ifdef HAVE_SCHED_YIELD -#define native_thread_yield() (void)sched_yield() -#else -#define native_thread_yield() ((void)0) -#endif - static void native_thread_dedicated_inc(rb_vm_t *vm, rb_ractor_t *cr, struct rb_native_thread *nt); static void native_thread_dedicated_dec(rb_vm_t *vm, rb_ractor_t *cr, struct rb_native_thread *nt); static void native_thread_assign(struct rb_native_thread *nt, rb_thread_t *th); |
