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

ruby-changes:31171

From: ko1 <ko1@a...>
Date: Fri, 11 Oct 2013 16:54:31 +0900 (JST)
Subject: [ruby-changes:31171] ko1:r43250 (trunk): * vm_trace.c (rb_postponed_job_flush): simplify.

ko1	2013-10-11 16:54:26 +0900 (Fri, 11 Oct 2013)

  New Revision: 43250

  http://svn.ruby-lang.org/cgi-bin/viewvc.cgi?view=rev&revision=43250

  Log:
    * vm_trace.c (rb_postponed_job_flush): simplify.

  Modified files:
    trunk/ChangeLog
    trunk/vm_trace.c
Index: ChangeLog
===================================================================
--- ChangeLog	(revision 43249)
+++ ChangeLog	(revision 43250)
@@ -1,3 +1,7 @@ https://github.com/ruby/ruby/blob/trunk/ChangeLog#L1
+Fri Oct 11 16:53:28 2013  Koichi Sasada  <ko1@a...>
+
+	* vm_trace.c (rb_postponed_job_flush): simplify.
+
 Fri Oct 11 03:36:49 2013  Nobuyoshi Nakada  <nobu@r...>
 
 	* thread.c (rb_threadptr_execute_interrupts): flush postponed job only
Index: vm_trace.c
===================================================================
--- vm_trace.c	(revision 43249)
+++ vm_trace.c	(revision 43250)
@@ -1444,46 +1444,25 @@ rb_postponed_job_register_one(unsigned i https://github.com/ruby/ruby/blob/trunk/vm_trace.c#L1444
 void
 rb_postponed_job_flush(rb_vm_t *vm)
 {
-    rb_thread_t *cur_th = GET_THREAD();
-    volatile struct {
-	rb_thread_t *thread;
-	unsigned long interrupt_mask;
-	int index, old_index;
-    } save;
-    int index = vm->postponed_job_index, old_index = index;
+    rb_thread_t *th = GET_THREAD();
+    unsigned long saved_postponed_job_interrupt_mask = th->interrupt_mask & POSTPONED_JOB_INTERRUPT_MASK;
 
-    save.thread = cur_th;
-    save.index = index;
-    save.interrupt_mask = cur_th->interrupt_mask;
-
-    cur_th->interrupt_mask |= POSTPONED_JOB_INTERRUPT_MASK;
-    TH_PUSH_TAG(cur_th);
-    EXEC_TAG();
-    /* ignore all jumps, just continue */
-    cur_th = save.thread;
-    index = save.index;
-    old_index = save.old_index;
-    while (index > 0) {
-	rb_postponed_job_t *pjob = &vm->postponed_job_buffer[--index];
-	void *data = pjob->data;
-	rb_postponed_job_func_t func = pjob->func;
-
-	pjob->func = 0;		/* not to execute again */
-	if (old_index > 0) {
-	    if (ATOMIC_CAS(vm->postponed_job_index, old_index, index) == old_index) {
-		old_index = index;
+    /* mask POSTPONED_JOB dispatch */
+    th->interrupt_mask |= POSTPONED_JOB_INTERRUPT_MASK;
+    {
+	TH_PUSH_TAG(th);
+	EXEC_TAG();
+	{
+	    int index;
+	    while ((index = vm->postponed_job_index) > 0) {
+		if (ATOMIC_CAS(vm->postponed_job_index, index, index-1) == index) {
+		    rb_postponed_job_t *pjob = &vm->postponed_job_buffer[index-1];
+		    (*pjob->func)(pjob->data);
+		}
 	    }
-	    else {
-		old_index = 0;
-	    }
-	}
-	save.index = index;
-	save.old_index = old_index;
-	if (func) {
-	    /* do postponed job */
-	    (*func)(data);
 	}
+	TH_POP_TAG();
     }
-    TH_POP_TAG();
-    cur_th->interrupt_mask = save.interrupt_mask;
+    /* restore POSTPONED_JOB mask */
+    th->interrupt_mask &= ~saved_postponed_job_interrupt_mask;
 }

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

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