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

ruby-changes:14059

From: nobu <ko1@a...>
Date: Fri, 20 Nov 2009 08:26:42 +0900 (JST)
Subject: [ruby-changes:14059] Ruby:r25870 (mvm): * vm.c (rb_vm_start): handshake.

nobu	2009-11-20 08:15:55 +0900 (Fri, 20 Nov 2009)

  New Revision: 25870

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

  Log:
    * vm.c (rb_vm_start): handshake.

  Modified files:
    branches/mvm/ChangeLog
    branches/mvm/eval.c
    branches/mvm/include/ruby/vm.h
    branches/mvm/mvm.c
    branches/mvm/vm.c

Index: mvm/include/ruby/vm.h
===================================================================
--- mvm/include/ruby/vm.h	(revision 25869)
+++ mvm/include/ruby/vm.h	(revision 25870)
@@ -23,7 +23,7 @@
 int ruby_vm_run(ruby_vm_t *vm, int *signo);
 int ruby_vm_run_node(ruby_vm_t *vm, void *n);
 int ruby_vm_exec_node(ruby_vm_t *vm, void *n);
-int ruby_vm_start(ruby_vm_t *vm);
+int ruby_vm_start(ruby_vm_t *vm, int status, int *signo);
 int ruby_vm_join(ruby_vm_t *vm);
 int ruby_vm_cleanup(ruby_vm_t *vm, int ex, int *signo);
 int ruby_vm_destruct(ruby_vm_t *vm);
Index: mvm/ChangeLog
===================================================================
--- mvm/ChangeLog	(revision 25869)
+++ mvm/ChangeLog	(revision 25870)
@@ -1,3 +1,7 @@
+Fri Nov 20 08:15:45 2009  Nobuyoshi Nakada  <nobu@r...>
+
+	* vm.c (rb_vm_start): handshake.
+
 Fri Nov 20 08:14:53 2009  Nobuyoshi Nakada  <nobu@r...>
 
 	* string.c (rb_str_copy_to_vm): reset instance variables.
Index: mvm/eval.c
===================================================================
--- mvm/eval.c	(revision 25869)
+++ mvm/eval.c	(revision 25870)
@@ -76,6 +76,8 @@
 {
     int state;
 
+    if (vm->running) return 0;
+
     PUSH_TAG();
     if ((state = EXEC_TAG()) == 0) {
 	rb_vm_call_inits();
@@ -275,12 +277,17 @@
 int
 ruby_vm_run(rb_vm_t *vm, int *signo)
 {
-    int status;
+    return ruby_vm_start(vm, ruby_vm_init(vm), signo);
+}
+
+int
+ruby_vm_start(rb_vm_t *vm, int status, int *signo)
+{
     void *n;
 
     rb_thread_set_current_raw(vm->main_thread);
     Init_stack((void *)&vm);
-    if ((status = ruby_vm_init(vm)) != 0) {
+    if (status != 0) {
 	return ruby_vm_cleanup(vm, status, signo);
     }
     n = ruby_vm_parse_options(vm);
Index: mvm/mvm.c
===================================================================
--- mvm/mvm.c	(revision 25869)
+++ mvm/mvm.c	(revision 25870)
@@ -35,13 +35,6 @@
 }
 
 int
-ruby_vm_start(rb_vm_t *vm)
-{
-    rb_bug("unsupporeted");
-    return 0;
-}
-
-int
 ruby_vm_join(rb_vm_t *vm)
 {
     return vm_join(vm);
@@ -232,6 +225,12 @@
     return vm == vm_manager.main;
 }
 
+void
+ruby_vmmgr_add(rb_vm_t *vm)
+{
+    vmmgr_add(vm);
+}
+
 static void
 vmmgr_add(rb_vm_t *vm)
 {
Index: mvm/vm.c
===================================================================
--- mvm/vm.c	(revision 25869)
+++ mvm/vm.c	(revision 25870)
@@ -2036,16 +2036,34 @@
 
 static rb_thread_t *vm_make_main_thread(rb_vm_t *vm);
 
+struct vm_create_args {
+    rb_vm_t *vm;
+    rb_thread_lock_t lock;
+    rb_thread_cond_t waiting;
+    volatile int initialized;
+};
+
+void ruby_vmmgr_add(rb_vm_t *);
+
 static VALUE
 vm_create(void *arg)
 {
-    rb_vm_t *vm = arg;
+    int ruby_executable_node(void *, int *);
+    void *ruby_vm_parse_options(rb_vm_t *);
+    struct vm_create_args *args = (void *)arg;
+    rb_vm_t *vm = args->vm;
     int status;
+
+    vm->ref_count++;
+    ruby_native_thread_lock(&args->lock);
     ruby_native_thread_unlock(&vm->global_vm_lock);
-    vm->ref_count++;
-    status = ruby_vm_run(vm, 0);
-    ruby_native_cond_signal(&vm->global_vm_waiting);
-    return (VALUE)status;
+    status = ruby_vm_init(vm);
+    if (!status) ruby_vmmgr_add(vm);
+    args->initialized = 1;
+    ruby_native_cond_signal(&args->waiting);
+    ruby_native_thread_unlock(&args->lock);
+
+    return (VALUE)ruby_vm_start(vm, status, 0);
 }
 
 static VALUE
@@ -2053,15 +2071,31 @@
 {
     rb_vm_t *vm;
     rb_thread_t *th;
+    struct vm_create_args args;
 
     GetVMPtr(self, vm);
     if (vm->main_thread) rb_raise(rb_eArgError, "alread started");
+
     th = vm_make_main_thread(vm);
     th->first_func = vm_create;
     th->first_proc = Qfalse;
-    th->first_args = (VALUE)vm;
+    th->first_args = (VALUE)&args;
+
+    args.vm = vm;
+    args.initialized = 0;
+    ruby_native_thread_lock_initialize(&args.lock);
+    ruby_native_cond_initialize(&args.waiting);
+    ruby_native_thread_lock(&args.lock);
+
     ruby_native_thread_create(th);
     ruby_native_thread_unlock(&vm->global_vm_lock);
+
+    while (!args.initialized) {
+	ruby_native_cond_wait(&args.waiting, &args.lock);
+    }
+    ruby_native_thread_unlock(&args.lock);
+    ruby_native_cond_destroy(&args.waiting);
+    ruby_native_thread_lock_destroy(&args.lock);
     return self;
 }
 

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

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