@@ -102,7 +102,6 @@ static const void *const condattr_monotonic = NULL;
102102
103103// process-global: deferred thread waiter
104104static struct {
105- bool running ;
106105 pthread_t thread ;
107106
108107 // Do not wait for any other lock while holding this one. The scheduler lock
@@ -119,6 +118,7 @@ static struct {
119118 // and the rb_thread_sched lock.
120119 struct ccan_list_head q_head ;
121120} thread_deferred_wait ;
121+ static bool thread_deferred_wait_running = false;
122122
123123// native thread wrappers
124124
@@ -1240,7 +1240,7 @@ deferred_wait_thread_worker(void *arg)
12401240 rb_native_mutex_lock (& thread_deferred_wait .lock );
12411241 }
12421242 else {
1243- if (!thread_deferred_wait . running ) {
1243+ if (!thread_deferred_wait_running ) {
12441244 break ;
12451245 }
12461246 VM_ASSERT (ccan_list_empty (& thread_deferred_wait .q_head ));
@@ -1281,7 +1281,7 @@ deferred_wait_thread_enqueue_yield(struct rb_thread_sched *sched, rb_thread_t *t
12811281 rb_native_mutex_lock (& thread_deferred_wait .lock );
12821282 // We held the sched lock while waiting for the mutex so we should not have been unlinked.
12831283 VM_ASSERT (!ccan_node_linked (& sched -> deferred_wait_link ));
1284- if (!thread_deferred_wait . running ) {
1284+ if (!thread_deferred_wait_running ) {
12851285 // Deferred waiter is stopped. Fall back.
12861286 rb_native_mutex_unlock (& thread_deferred_wait .lock );
12871287 return false;
@@ -1330,6 +1330,7 @@ thread_sched_blocking_region_exit(struct rb_thread_sched *sched, rb_thread_t *th
13301330void
13311331rb_thread_start_deferred_wait_thread (bool init )
13321332{
1333+ VM_ASSERT (!thread_deferred_wait_running );
13331334 if (init ) {
13341335 rb_native_mutex_initialize (& thread_deferred_wait .lock );
13351336 rb_native_cond_initialize (& thread_deferred_wait .cond );
@@ -1347,14 +1348,16 @@ rb_thread_start_deferred_wait_thread(bool init)
13471348 rb_bug_errno ("start_deferred_wait_thread - pthread_create" , r );
13481349 }
13491350 pthread_attr_destroy (& attr );
1350- thread_deferred_wait . running = true;
1351+ thread_deferred_wait_running = true;
13511352}
13521353
13531354void
13541355rb_thread_stop_deferred_wait_thread (bool destroy )
13551356{
1357+ VM_ASSERT (thread_deferred_wait_running );
1358+
13561359 rb_native_mutex_lock (& thread_deferred_wait .lock );
1357- thread_deferred_wait . running = false;
1360+ thread_deferred_wait_running = false;
13581361 rb_native_cond_signal (& thread_deferred_wait .cond );
13591362 rb_native_mutex_unlock (& thread_deferred_wait .lock );
13601363 pthread_join (thread_deferred_wait .thread , NULL );
0 commit comments