[macruby-changes] [2104] MacRuby/branches/experimental/thread.c

source_changes at macosforge.org source_changes at macosforge.org
Tue Jul 28 00:33:26 PDT 2009


Revision: 2104
          http://trac.macosforge.org/projects/ruby/changeset/2104
Author:   lsansonetti at apple.com
Date:     2009-07-28 00:33:24 -0700 (Tue, 28 Jul 2009)
Log Message:
-----------
implemented Thread.start/fork

Modified Paths:
--------------
    MacRuby/branches/experimental/thread.c

Modified: MacRuby/branches/experimental/thread.c
===================================================================
--- MacRuby/branches/experimental/thread.c	2009-07-28 07:27:19 UTC (rev 2103)
+++ MacRuby/branches/experimental/thread.c	2009-07-28 07:33:24 UTC (rev 2104)
@@ -36,24 +36,7 @@
     return Data_Wrap_Struct(rb_cThread, NULL, NULL, t);
 }
 
-/*
- *  call-seq:
- *     Thread.start([args]*) {|args| block }   => thread
- *     Thread.fork([args]*) {|args| block }    => thread
- *
- *  Basically the same as <code>Thread::new</code>. However, if class
- *  <code>Thread</code> is subclassed, then calling <code>start</code> in that
- *  subclass will not invoke the subclass's <code>initialize</code> method.
- */
-
 static VALUE
-thread_start(VALUE klass, VALUE args)
-{
-    // TODO
-    return Qnil;
-}
-
-static VALUE
 thread_initialize(VALUE thread, SEL sel, int argc, const VALUE *argv)
 {
     if (!rb_block_given_p()) {
@@ -80,6 +63,23 @@
     return thread;
 }
 
+/*
+ *  call-seq:
+ *     Thread.start([args]*) {|args| block }   => thread
+ *     Thread.fork([args]*) {|args| block }    => thread
+ *
+ *  Basically the same as <code>Thread::new</code>. However, if class
+ *  <code>Thread</code> is subclassed, then calling <code>start</code> in that
+ *  subclass will not invoke the subclass's <code>initialize</code> method.
+ */
+
+static VALUE
+thread_start(VALUE klass, SEL sel, int argc, VALUE *argv)
+{
+    VALUE th = thread_s_alloc(klass, 0);
+    return thread_initialize(th, 0, argc, argv);
+}
+
 VALUE
 rb_thread_create(VALUE (*fn)(ANYARGS), void *arg)
 {
@@ -1444,9 +1444,8 @@
     rb_cThread = rb_define_class("Thread", rb_cObject);
     rb_objc_define_method(*(VALUE *)rb_cThread, "alloc", thread_s_alloc, 0);
 
-    //rb_define_singleton_method(rb_cThread, "new", thread_s_new, -1);
-    rb_define_singleton_method(rb_cThread, "start", thread_start, -2);
-    rb_define_singleton_method(rb_cThread, "fork", thread_start, -2);
+    rb_objc_define_method(*(VALUE *)rb_cThread, "start", thread_start, -1);
+    rb_objc_define_method(*(VALUE *)rb_cThread, "fork", thread_start, -1);
     rb_objc_define_method(*(VALUE *)rb_cThread, "main", rb_thread_s_main, 0);
     rb_objc_define_method(*(VALUE *)rb_cThread, "current", thread_s_current, 0);
     rb_objc_define_method(*(VALUE *)rb_cThread, "stop", rb_thread_stop, 0);
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://lists.macosforge.org/pipermail/macruby-changes/attachments/20090728/11f34523/attachment-0001.html>


More information about the macruby-changes mailing list