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

ruby-changes:13770

From: nobu <ko1@a...>
Date: Fri, 30 Oct 2009 10:55:53 +0900 (JST)
Subject: [ruby-changes:13770] Ruby:r25566 (trunk): * thread.c (rb_thread_blocking_region): must ensure to unlock GVL.

nobu	2009-10-30 10:55:38 +0900 (Fri, 30 Oct 2009)

  New Revision: 25566

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

  Log:
    * thread.c (rb_thread_blocking_region): must ensure to unlock GVL.
      [ruby-dev:39579]

  Modified files:
    trunk/ChangeLog
    trunk/thread.c

Index: ChangeLog
===================================================================
--- ChangeLog	(revision 25565)
+++ ChangeLog	(revision 25566)
@@ -1,3 +1,8 @@
+Fri Oct 30 10:55:36 2009  Nobuyoshi Nakada  <nobu@r...>
+
+	* thread.c (rb_thread_blocking_region): must ensure to unlock GVL.
+	  [ruby-dev:39579]
+
 Fri Oct 30 04:47:26 2009  Nobuyoshi Nakada  <nobu@r...>
 
 	* include/ruby/ruby.h (RSTRING_END): trivial optimization.
Index: thread.c
===================================================================
--- thread.c	(revision 25565)
+++ thread.c	(revision 25566)
@@ -1028,6 +1028,23 @@
     RUBY_VM_CHECK_INTS();
 }
 
+#ifndef PROHIBIT_FUNCTION_CAST
+#define PROHIBIT_FUNCTION_CAST 0
+#endif
+#if PROHIBIT_FUNCTION_CAST
+struct blocking_function_args {
+    rb_blocking_function_t *func;
+    void *data;
+};
+
+static VALUE
+call_blocking_function(VALUE arg)
+{
+    struct blocking_function_args *blocking = (void *)arg;
+    return (blocking->func)(blocking->data);
+}
+#endif
+
 /*
  * rb_thread_blocking_region - permit concurrent/parallel execution.
  *
@@ -1070,6 +1087,10 @@
 {
     VALUE val;
     rb_thread_t *th = GET_THREAD();
+    int status;
+#if PROHIBIT_FUNCTION_CAST
+    struct blocking_function_args args;
+#endif
 
     if (ubf == RUBY_UBF_IO || ubf == RUBY_UBF_PROCESS) {
 	ubf = ubf_select;
@@ -1077,8 +1098,15 @@
     }
 
     BLOCKING_REGION({
-	val = func(data1);
+#if PROHIBIT_FUNCTION_CAST
+	args.func = func;
+	args.data = data1;
+	val = rb_protect(call_blocking_function, (VALUE)&args, &status);
+#else
+	val = rb_protect((VALUE (*)(VALUE))func, (VALUE)data1, &status);
+#endif
     }, ubf, data2);
+    if (status) rb_jump_tag(status);
 
     return val;
 }

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

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