From 0e3b0fcdba70cf96a8e0654eb8f50aacb8024bd4 Mon Sep 17 00:00:00 2001 From: Samuel Williams Date: Thu, 14 May 2020 22:10:55 +1200 Subject: Thread scheduler for light weight concurrency. --- thread_sync.c | 7 ++++++- 1 file changed, 6 insertions(+), 1 deletion(-) (limited to 'thread_sync.c') diff --git a/thread_sync.c b/thread_sync.c index 2e20812f4d..3689dee789 100644 --- a/thread_sync.c +++ b/thread_sync.c @@ -190,6 +190,8 @@ mutex_locked(rb_thread_t *th, VALUE self) mutex->next_mutex = th->keeping_mutexes; } th->keeping_mutexes = mutex; + + th->blocking += 1; } /* @@ -365,6 +367,8 @@ rb_mutex_unlock_th(rb_mutex_t *mutex, rb_thread_t *th) struct sync_waiter *cur = 0, *next; rb_mutex_t **th_mutex = &th->keeping_mutexes; + th->blocking -= 1; + mutex->th = 0; list_for_each_safe(&mutex->waitq, cur, next, node) { list_del_init(&cur->node); @@ -404,8 +408,9 @@ rb_mutex_unlock(VALUE self) { const char *err; rb_mutex_t *mutex = mutex_ptr(self); + rb_thread_t *th = GET_THREAD(); - err = rb_mutex_unlock_th(mutex, GET_THREAD()); + err = rb_mutex_unlock_th(mutex, th); if (err) rb_raise(rb_eThreadError, "%s", err); return self; -- cgit v1.2.3