[前][次][番号順一覧][スレッド一覧]

ruby-changes:51634

From: normal <ko1@a...>
Date: Wed, 4 Jul 2018 10:26:37 +0900 (JST)
Subject: [ruby-changes:51634] normal:r63846 (trunk): thread_pthread.c: pass rb_vm_t to timer_thread_sleep

normal	2018-07-04 10:26:31 +0900 (Wed, 04 Jul 2018)

  New Revision: 63846

  https://svn.ruby-lang.org/cgi-bin/viewvc.cgi?view=revision&revision=63846

  Log:
    thread_pthread.c: pass rb_vm_t to timer_thread_sleep
    
    I love `container_of' for generic data structures, but
    in this case it's unnecessary and slightly harder-to-read.
    
    This will make "Timeout in VM" slightly easier-to-read:
    https://bugs.ruby-lang.org/issues/14859

  Modified files:
    trunk/thread_pthread.c
Index: thread_pthread.c
===================================================================
--- thread_pthread.c	(revision 63845)
+++ thread_pthread.c	(revision 63846)
@@ -1369,7 +1369,7 @@ setup_communication_pipe(void) https://github.com/ruby/ruby/blob/trunk/thread_pthread.c#L1369
  * @pre the calling context is in the timer thread.
  */
 static inline void
-timer_thread_sleep(rb_global_vm_lock_t* gvl)
+timer_thread_sleep(rb_vm_t *vm)
 {
     int result;
     int need_polling;
@@ -1383,8 +1383,6 @@ timer_thread_sleep(rb_global_vm_lock_t* https://github.com/ruby/ruby/blob/trunk/thread_pthread.c#L1383
     need_polling = !ubf_threads_empty();
 
     if (SIGCHLD_LOSSY && !need_polling) {
-        rb_vm_t *vm = container_of(gvl, rb_vm_t, gvl);
-
         rb_native_mutex_lock(&vm->waitpid_lock);
         if (!list_empty(&vm->waiting_pids) || !list_empty(&vm->waiting_grps)) {
             need_polling = 1;
@@ -1392,7 +1390,7 @@ timer_thread_sleep(rb_global_vm_lock_t* https://github.com/ruby/ruby/blob/trunk/thread_pthread.c#L1390
         rb_native_mutex_unlock(&vm->waitpid_lock);
     }
 
-    if (gvl->waiting > 0 || need_polling) {
+    if (vm->gvl.waiting > 0 || need_polling) {
 	/* polling (TIME_QUANTUM_USEC usec) */
 	result = poll(pollfds, 1, TIME_QUANTUM_USEC/1000);
     }
@@ -1431,7 +1429,7 @@ static rb_nativethread_lock_t timer_thre https://github.com/ruby/ruby/blob/trunk/thread_pthread.c#L1429
 static rb_nativethread_cond_t timer_thread_cond;
 
 static inline void
-timer_thread_sleep(rb_global_vm_lock_t* unused)
+timer_thread_sleep(rb_vm_t *unused)
 {
     struct timespec ts;
     ts.tv_sec = 0;
@@ -1495,7 +1493,7 @@ native_set_another_thread_name(rb_native https://github.com/ruby/ruby/blob/trunk/thread_pthread.c#L1493
 static void *
 thread_timer(void *p)
 {
-    rb_global_vm_lock_t *gvl = (rb_global_vm_lock_t *)p;
+    rb_vm_t *vm = p;
 #ifdef HAVE_PTHREAD_SIGMASK /* mainly to enable SIGCHLD */
     {
         sigset_t mask;
@@ -1524,7 +1522,7 @@ thread_timer(void *p) https://github.com/ruby/ruby/blob/trunk/thread_pthread.c#L1522
 	if (TT_DEBUG) WRITE_CONST(2, "tick\n");
 
         /* wait */
-	timer_thread_sleep(gvl);
+	timer_thread_sleep(vm);
     }
 #if USE_SLEEPY_TIMER_THREAD
     CLOSE_INVALIDATE(normal[0]);
@@ -1596,7 +1594,7 @@ rb_thread_create_timer_thread(void) https://github.com/ruby/ruby/blob/trunk/thread_pthread.c#L1594
 	if (timer_thread.created) {
 	    rb_bug("rb_thread_create_timer_thread: Timer thread was already created\n");
 	}
-	err = pthread_create(&timer_thread.id, &attr, thread_timer, &vm->gvl);
+	err = pthread_create(&timer_thread.id, &attr, thread_timer, vm);
 	pthread_attr_destroy(&attr);
 
 	if (err == EINVAL) {
@@ -1607,7 +1605,7 @@ rb_thread_create_timer_thread(void) https://github.com/ruby/ruby/blob/trunk/thread_pthread.c#L1605
 	     * default stack size is enough for them:
 	     */
 	    stack_size = 0;
-	    err = pthread_create(&timer_thread.id, NULL, thread_timer, &vm->gvl);
+	    err = pthread_create(&timer_thread.id, NULL, thread_timer, vm);
 	}
 	if (err != 0) {
 	    rb_warn("pthread_create failed for timer: %s, scheduling broken",

--
ML: ruby-changes@q...
Info: http://www.atdot.net/~ko1/quickml/

[前][次][番号順一覧][スレッド一覧]