[macruby-changes] [2667] MacRuby/trunk

source_changes at macosforge.org source_changes at macosforge.org
Mon Sep 28 19:10:23 PDT 2009


Revision: 2667
          http://trac.macosforge.org/projects/ruby/changeset/2667
Author:   lsansonetti at apple.com
Date:     2009-09-28 19:10:23 -0700 (Mon, 28 Sep 2009)
Log Message:
-----------
make sure RoxorVM instances created lazily have a valid thread accessor

Modified Paths:
--------------
    MacRuby/trunk/vm.cpp
    MacRuby/trunk/vm.h

Modified: MacRuby/trunk/vm.cpp
===================================================================
--- MacRuby/trunk/vm.cpp	2009-09-29 02:09:16 UTC (rev 2666)
+++ MacRuby/trunk/vm.cpp	2009-09-29 02:10:23 UTC (rev 2667)
@@ -5632,22 +5632,31 @@
     rb_vm_set_current_scope(rb_cNSObject, SCOPE_PRIVATE);
 }
 
-extern "C"
 void
-Init_PostVM(void)
+RoxorVM::setup_from_current_thread(void)
 {
-    // Create and register the main thread.
-    RoxorVM *main_vm = GET_VM();
+    pthread_setspecific(RoxorVM::vm_thread_key, (void *)this);
+
     rb_vm_thread_t *t = (rb_vm_thread_t *)xmalloc(sizeof(rb_vm_thread_t));
-    rb_vm_thread_pre_init(t, NULL, 0, NULL, (void *)main_vm);
+    rb_vm_thread_pre_init(t, NULL, 0, NULL, (void *)this);
     t->thread = pthread_self();
+
     VALUE main = Data_Wrap_Struct(rb_cThread, NULL, NULL, t);
     GET_CORE()->register_thread(main);
-    main_vm->set_thread(main);
+    this->set_thread(main);
+}
 
+extern "C"
+void
+Init_PostVM(void)
+{
+    // Create and register the main thread.
+    RoxorVM *main_vm = GET_VM();
+    main_vm->setup_from_current_thread();
+
     // Create main thread group.
     VALUE group = rb_obj_alloc(rb_cThGroup);
-    rb_thgroup_add(group, main);
+    rb_thgroup_add(group, main_vm->get_thread());
     rb_define_const(rb_cThGroup, "Default", group);
 }
 

Modified: MacRuby/trunk/vm.h
===================================================================
--- MacRuby/trunk/vm.h	2009-09-29 02:09:16 UTC (rev 2666)
+++ MacRuby/trunk/vm.h	2009-09-29 02:10:23 UTC (rev 2667)
@@ -779,6 +779,7 @@
 		    // XXX the VM object is never detroyed.
 		    RoxorVM *new_vm = new RoxorVM();
 		    pthread_setspecific(vm_thread_key, (void *)new_vm);
+		    new_vm->setup_from_current_thread();
 		    return new_vm;
 		}
 		return (RoxorVM *)vm;
@@ -917,6 +918,8 @@
 
 	VALUE ruby_catch(VALUE tag);
 	VALUE ruby_throw(VALUE tag, VALUE value);
+
+	void setup_from_current_thread(void);
 };
 
 #define GET_VM() (RoxorVM::current())
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://lists.macosforge.org/pipermail/macruby-changes/attachments/20090928/86d97c3f/attachment-0001.html>


More information about the macruby-changes mailing list