[前][次][番号順一覧][スレッド一覧][生データ]

yarv-diff:292

From: ko1 atdot.net
Date: 21 Feb 2006 12:09:54 -0000
Subject: [yarv-diff:292] r456 - in trunk: . ext/win32ole test/ruby

Author: ko1
Date: 2006-02-21 21:09:54 +0900 (Tue, 21 Feb 2006)
New Revision: 456

Modified:
   trunk/
   trunk/ChangeLog
   trunk/eval.c
   trunk/eval_jump.h
   trunk/eval_thread.c
   trunk/ext/win32ole/.document
   trunk/insns.def
   trunk/intern.h
   trunk/signal.c
   trunk/test.rb
   trunk/test/ruby/test_beginendblock.rb
   trunk/thread.c
   trunk/thread_pthread.h
   trunk/thread_win32.h
   trunk/vm_dump.c
   trunk/yarv.h
   trunk/yarvcore.c
   trunk/yarvcore.h
Log:
 r698@lermite:  ko1 | 2006-02-21 21:05:37 +0900
 	* eval.c : fix place of rb_thread_terminate_all()
 
 	* eval_thread.c : remove unused functions
 
 	* yarv.h : remove GET_VM()
 
 	* eval_jump.h : ditto
 
 	* insns.def : ditto
 
 	* vm_dump.c : 
 
 	* intern.h : change rb_thread_signal_raise/exit interface
 
 	* signal.c : ditto
 
 	* thread.c : ditto
 
 	* test/ruby/test_beginendblock.rb : use block with IO.popen
 
 	* thread_pthread.h : fix interrupt process
 
 	* thread_win32.h : ditto
 
 	* yarvcore.c : fix thread free process
 
 	* yarvcore.h : remove yarv_vm_t#thread_critical, etc
 



Property changes on: trunk
___________________________________________________________________
Name: svk:merge
   - 81cd9672-7512-7e48-ae48-6936450e977d:/local/yarv/trunk:696
   + 81cd9672-7512-7e48-ae48-6936450e977d:/local/yarv/trunk:698

Modified: trunk/ChangeLog
===================================================================
--- trunk/ChangeLog	2006-02-21 04:09:30 UTC (rev 455)
+++ trunk/ChangeLog	2006-02-21 12:09:54 UTC (rev 456)
@@ -4,6 +4,37 @@
 #  from Mon, 03 May 2004 01:24:19 +0900
 #
 
+2006-02-21(Tue) 20:54:28 +0900  Koichi Sasada  <ko1 atdot.net>
+
+	* eval.c : fix place of rb_thread_terminate_all()
+
+	* eval_thread.c : remove unused functions
+
+	* yarv.h : remove GET_VM()
+
+	* eval_jump.h : ditto
+
+	* insns.def : ditto
+
+	* vm_dump.c : 
+
+	* intern.h : change rb_thread_signal_raise/exit interface
+
+	* signal.c : ditto
+
+	* thread.c : ditto
+
+	* test/ruby/test_beginendblock.rb : use block with IO.popen
+
+	* thread_pthread.h : fix interrupt process
+
+	* thread_win32.h : ditto
+
+	* yarvcore.c : fix thread free process
+
+	* yarvcore.h : remove yarv_vm_t#thread_critical, etc
+
+
 2006-02-21(Tue) 12:42:44 +0900  Koichi Sasada  <ko1 atdot.net>
 
 	* eval_thread.c : remove unused function rb_thread_schedule()

Modified: trunk/eval.c
===================================================================
--- trunk/eval.c	2006-02-21 04:09:30 UTC (rev 455)
+++ trunk/eval.c	2006-02-21 12:09:54 UTC (rev 456)
@@ -212,10 +212,8 @@
 {
     int state;
     volatile VALUE err = GET_THREAD()->errinfo;
-    yarv_vm_t *vm = GET_VM();
+    yarv_vm_t *vm = GET_THREAD()->vm;
 
-    rb_thread_terminate_all();
-
     /* th->errinfo contains a NODE while break'ing */
     if (RTEST(err) && (TYPE(err) != T_NODE) &&
 	rb_obj_is_kind_of(err, rb_eSystemExit)) {
@@ -233,12 +231,11 @@
 	    err = GET_THREAD()->errinfo;
 	}
 	ruby_finalize_0();
-	rb_thread_cleanup();
-	rb_thread_wait_other_threads();
     }
     else if (ex == 0) {
 	ex = state;
     }
+    rb_thread_terminate_all();
     GET_THREAD()->errinfo = err;
     ex = error_handle(ex);
     ruby_finalize_1();

Modified: trunk/eval_jump.h
===================================================================
--- trunk/eval_jump.h	2006-02-21 04:09:30 UTC (rev 455)
+++ trunk/eval_jump.h	2006-02-21 12:09:54 UTC (rev 456)
@@ -144,7 +144,7 @@
 terminate_process(int status, const char *mesg, long mlen)
 {
     VALUE args[2];
-    yarv_vm_t *vm = GET_VM();
+    yarv_vm_t *vm = GET_THREAD()->vm;
 
     args[0] = INT2NUM(status);
     args[1] = rb_str_new(mesg, mlen);

Modified: trunk/eval_thread.c
===================================================================
--- trunk/eval_thread.c	2006-02-21 04:09:30 UTC (rev 455)
+++ trunk/eval_thread.c	2006-02-21 12:09:54 UTC (rev 456)
@@ -559,18 +559,6 @@
  *  subclass will not invoke the subclass's <code>initialize</code> method.
  */
 
-void
-rb_thread_wait_other_threads()
-{
-    // TODO: fix me
-}
-
-void
-rb_thread_cleanup()
-{
-    // TODO: fix me
-}
-
 int rb_thread_critical;
 
 

Modified: trunk/ext/win32ole/.document
===================================================================
--- trunk/ext/win32ole/.document	2006-02-21 04:09:30 UTC (rev 455)
+++ trunk/ext/win32ole/.document	2006-02-21 12:09:54 UTC (rev 456)
@@ -0,0 +1 @@
+win32ole.c

Modified: trunk/insns.def
===================================================================
--- trunk/insns.def	2006-02-21 04:09:30 UTC (rev 455)
+++ trunk/insns.def	2006-02-21 12:09:54 UTC (rev 456)
@@ -987,7 +987,7 @@
 ()
 {
     /* TODO: trace instruction design */
-    if (GET_VM()->trace_flag & flag) {
+    if (th->vm->trace_flag & flag) {
 	/* */
 	args = Qnil;
     }

Modified: trunk/intern.h
===================================================================
--- trunk/intern.h	2006-02-21 04:09:30 UTC (rev 455)
+++ trunk/intern.h	2006-02-21 12:09:54 UTC (rev 456)
@@ -272,8 +272,8 @@
 VALUE rb_thread_create(VALUE (*)(ANYARGS), void*);
 void rb_thread_interrupt(void);
 void rb_thread_trap_eval(VALUE, int, int);
-void rb_thread_signal_raise(const char*); /* should pass literal */
-void rb_thread_signal_exit(void);
+void rb_thread_signal_raise(void *, const char*); /* should pass literal */
+void rb_thread_signal_exit(void *);
 int rb_thread_select(int, fd_set *, fd_set *, fd_set *, struct timeval *);
 void rb_thread_wait_for(struct timeval);
 VALUE rb_thread_current(void);

Modified: trunk/signal.c
===================================================================
--- trunk/signal.c	2006-02-21 04:09:30 UTC (rev 455)
+++ trunk/signal.c	2006-02-21 12:09:54 UTC (rev 456)
@@ -414,7 +414,7 @@
 static RETSIGTYPE
 sighandler(int sig)
 {
-  yarv_thread_t *th = GET_VM()->main_thread;
+  yarv_thread_t *th = GET_THREAD()->vm->main_thread; // TODO: fix me
   int next_head = (th->signal_queue.head + 1) % RUBY_SIGNAL_QUEUE_MAX;
   
   if(next_head == th->signal_queue.tail){
@@ -515,12 +515,12 @@
 #ifdef SIGUSR2
     case SIGUSR2:
 #endif
-      rb_thread_signal_raise(signo2signm(sig));
+      rb_thread_signal_raise(th, signo2signm(sig));
       break;
     }
   }
   else if (cmd == Qundef) {
-    rb_thread_signal_exit();
+    rb_thread_signal_exit(th);
   }
   else {
     yarv_proc_t *proc;

Modified: trunk/test/ruby/test_beginendblock.rb
===================================================================
--- trunk/test/ruby/test_beginendblock.rb	2006-02-21 04:09:30 UTC (rev 455)
+++ trunk/test/ruby/test_beginendblock.rb	2006-02-21 12:09:54 UTC (rev 456)
@@ -10,12 +10,11 @@
   end
 
   def test_beginendblock
-#assert false, "TODO: BEGIN{} support is incomplete"
     ruby = EnvUtil.rubybin
     target = File.join(DIR, 'beginmainend.rb')
-    io = IO.popen("#{q(ruby)} #{q(target)}")
-    assert_equal(%w(b1 b2-1 b2 main b3-1 b3 b4 e1 e4 e3 e2 e4-2 e4-1 e1-1 e4-1-1), io.read.split)
-    io.close
+    IO.popen("#{q(ruby)} #{q(target)}"){|io|
+      assert_equal(%w(b1 b2-1 b2 main b3-1 b3 b4 e1 e4 e3 e2 e4-2 e4-1 e1-1 e4-1-1), io.read.split)
+    }
   end
 
   def test_begininmethod

Modified: trunk/test.rb
===================================================================
--- trunk/test.rb	2006-02-21 04:09:30 UTC (rev 455)
+++ trunk/test.rb	2006-02-21 12:09:54 UTC (rev 456)
@@ -1,7 +1,33 @@
+at_exit do
+  p :foo
+  main = nil
+  th = Thread.new do
+    Thread.stop
+    main.wakeup
+  end
+  Thread.pass until th.stop?
 
+  main = Thread.current
+  th.wakeup
+  Thread.stop
+end
 
 __END__
 
+
+print 'foobar'
+__END__
+Thread.new{
+
+}.join
+
+__END__
+
+p(      :sym =~ /sym/ )
+
+
+__END__
+
 class C
   define_method(:foo){
     return :bar

Modified: trunk/thread.c
===================================================================
--- trunk/thread.c	2006-02-21 04:09:30 UTC (rev 455)
+++ trunk/thread.c	2006-02-21 12:09:54 UTC (rev 456)
@@ -51,9 +51,6 @@
 struct timeval rb_time_interval(VALUE);
 static int rb_thread_dead(yarv_thread_t *th);
 
-static void yarv_add_signal_thread_list(yarv_thread_t *th);
-static void yarv_remove_signal_thread_list(yarv_thread_t *th);
-
 void rb_signal_exec(yarv_thread_t *th, int sig);
 static VALUE eKillSignal = INT2FIX(0);
 static VALUE eTerminateSignal = INT2FIX(1);
@@ -184,7 +181,7 @@
 thread_cleanup_func(void *th_ptr)
 {
     yarv_thread_t *th = th_ptr;
-    st_delete_wrap(GET_VM()->living_threads, th->self);
+    st_delete_wrap(th->vm->living_threads, th->self);
     th->status = THREAD_KILLED;
     th->machine_stack_start = th->machine_stack_end = 0;
 }
@@ -195,6 +192,7 @@
     int state;
     VALUE args = th->first_args;
     yarv_proc_t *proc;
+    yarv_thread_t *join_th;
     GetProcVal(th->first_proc, proc);
 
     th->machine_stack_start = stack_start;
@@ -202,7 +200,7 @@
 
     thread_debug("thread start: %p\n", th);
 
-    GVL_LOCK_BEGIN();
+    native_mutex_lock(&th->vm->global_interpreter_lock);
     {
 	yarv_set_current_running_thread(th);
 	thread_debug("get_lock, start: %p\n", th);
@@ -222,17 +220,16 @@
 	
 	th->status = THREAD_KILLED;
 	thread_debug("thread end: %p\n", th);
-	st_delete_wrap(GET_VM()->living_threads, th->self);
+	st_delete_wrap(th->vm->living_threads, th->self);
 
 	/* wake up joinning threads */
-	th = th->join_list_head;
-	while (th) {
-	    native_thread_interrupt(th);
-	    th = th->join_list_next;
+	join_th = th->join_list_head;
+	while (join_th) {
+	    native_thread_interrupt(join_th);
+	    join_th = join_th->join_list_next;
 	}
     }
-    GVL_LOCK_END();
-
+    native_mutex_unlock(&th->vm->global_interpreter_lock);
     return 0;
 }
 
@@ -252,7 +249,7 @@
 
     /* kick thread */
     native_thread_create(th);
-    st_insert(GET_VM()->living_threads, thval, (st_data_t) th->thread_id);
+    st_insert(th->vm->living_threads, thval, (st_data_t) th->thread_id);
     return thval;
 }
 
@@ -534,11 +531,11 @@
 
 	thread_debug("rb_thread_schedule/switch start\n");
 	yarv_save_machine_context(th);
-	native_mutex_unlock(&GET_VM()->global_interpreter_lock);
+	native_mutex_unlock(&th->vm->global_interpreter_lock);
 	{
 	    native_thread_yield();
 	}
-	native_mutex_lock(&GET_VM()->global_interpreter_lock);
+	native_mutex_lock(&th->vm->global_interpreter_lock);
 	yarv_set_current_running_thread(th);
 	thread_debug("rb_thread_schedule/switch done (thid: %p)\n",
 		     th->thread_id);
@@ -663,28 +660,31 @@
 }
 
 void
-rb_thread_signal_raise(const char *sig)
+rb_thread_signal_raise(void *thptr, const char *sig)
 {
     VALUE argv[1];
     char buf[BUFSIZ];
+    yarv_thread_t *th = thptr;
+    
     if (sig == 0) {
 	return;			/* should not happen */
     }
     snprintf(buf, BUFSIZ, "SIG%s", sig);
     argv[0] = rb_exc_new3(rb_eSignal, rb_str_new2(buf));
-    yarv_thread_raise(1, argv, GET_VM()->main_thread);
+    yarv_thread_raise(1, argv, th->vm->main_thread);
 }
 
 void
-rb_thread_signal_exit()
+rb_thread_signal_exit(void *thptr)
 {
     VALUE argv[1];
     VALUE args[2];
-
+    yarv_thread_t *th = thptr;
+    
     args[0] = INT2NUM(EXIT_SUCCESS);
     args[1] = rb_str_new2("exit");
     argv[0] = rb_class_new_instance(2, args, rb_eSystemExit);
-    yarv_thread_raise(1, argv, GET_VM()->main_thread);
+    yarv_thread_raise(1, argv, th->vm->main_thread);
 }
 
 
@@ -742,7 +742,7 @@
     if (th->status == THREAD_TO_KILL || th->status == THREAD_KILLED) {
 	return thread;
     }
-    if (th == GET_VM()->main_thread) {
+    if (th == th->vm->main_thread) {
 	rb_exit(EXIT_SUCCESS);
     }
     
@@ -931,7 +931,7 @@
 rb_thread_list(void)
 {
     VALUE ary = rb_ary_new();
-    st_foreach(GET_VM()->living_threads, thread_list_i, ary);
+    st_foreach(GET_THREAD()->vm->living_threads, thread_list_i, ary);
     return ary;
 }
 
@@ -950,10 +950,16 @@
     return GET_THREAD()->self;
 }
 
+VALUE
+rb_thread_main(void)
+{
+    return GET_THREAD()->vm->main_thread_val;
+}
+
 static VALUE
-yarv_thread_s_main(VALUE klass)
+rb_thread_s_main(VALUE klass)
 {
-    return GET_VM()->main_thread_val;
+    return rb_thread_main();
 }
 
 
@@ -972,7 +978,7 @@
 static VALUE
 rb_thread_s_abort_exc()
 {
-    return GET_VM()->thread_abort_on_exception ? Qtrue : Qfalse;
+    return GET_THREAD()->vm->thread_abort_on_exception ? Qtrue : Qfalse;
 }
 
 
@@ -1004,7 +1010,7 @@
 rb_thread_s_abort_exc_set(VALUE self, VALUE val)
 {
     rb_secure(4);
-    GET_VM()->thread_abort_on_exception = RTEST(val);
+    GET_THREAD()->vm->thread_abort_on_exception = RTEST(val);
     return val;
 }
 
@@ -1349,7 +1355,7 @@
 int
 rb_thread_alone()
 {
-    int num = GET_VM()->living_threads->num_entries;
+    int num = GET_THREAD()->vm->living_threads->num_entries;
     thread_debug("rb_thread_alone: %d\n", num);
     return num == 1;
 }
@@ -1553,88 +1559,12 @@
  *
  */
 
-struct yarv_signal_thread_list {
-    yarv_thread_t *th;
-    int need_signal;
-    struct yarv_signal_thread_list *prev;
-    struct yarv_signal_thread_list *next;
-};
 
-static struct yarv_signal_thread_list signal_thread_list_anchor = {
-    0, 0, 0, 0,
-};
-
-static yarv_thread_lock_t signal_thread_list_lock;
-
-#define FGLOCK(lock, body) do { \
-    native_mutex_lock(lock); \
-    { \
-	body; \
-    } \
-    native_mutex_unlock(lock); \
-} while (0)
-
 static void
-yarv_add_signal_thread_list(yarv_thread_t *th)
-{
-    if (!th->signal_thread_list) {
-	FGLOCK(&signal_thread_list_lock, {
-	    struct yarv_signal_thread_list *list =
-	      xmalloc(sizeof(struct yarv_signal_thread_list));
-	    list->th = th;
-
-	    list->prev = &signal_thread_list_anchor;
-	    list->next = signal_thread_list_anchor.next;
-	    if (list->next) {
-		list->next->prev = list;
-	    }
-	    signal_thread_list_anchor.next = list;
-	    th->signal_thread_list = list;
-	});
-    }
-}
-
-static void
-yarv_remove_signal_thread_list(yarv_thread_t *th)
-{
-    if (th->signal_thread_list) {
-	FGLOCK(&signal_thread_list_lock, {
-	    struct yarv_signal_thread_list *list =
-	      (struct yarv_signal_thread_list *)th->signal_thread_list;
-
-	    list->prev->next = list->next;
-	    if (list->next) {
-		list->next->prev = list->prev;
-	    }
-	    th->signal_thread_list = 0;
-	    list->th = 0;
-	    xfree(list);
-	});
-    }
-    else {
-	/* */
-    }
-}
-
-static void
 timer_function(void)
 {
-
     // TODO: GET_VM() should not be used
-    GET_VM()->running_thread->interrupt_flag = 1;
-
-#ifndef _WIN32
-    if (signal_thread_list_anchor.next) {
-	FGLOCK(&signal_thread_list_lock, {
-	    struct yarv_signal_thread_list *list;
-	    list = signal_thread_list_anchor.next;
-	    while (list) {
-		native_thread_send_interrupt_signal(list->th);
-		list = list->next;
-	    }
-	});
-    }
-#endif
+    GET_THREAD()->vm->running_thread->interrupt_flag = 1;
 }
 
 /*
@@ -1723,7 +1653,7 @@
     struct thgroup_list_params param = {
 	ary, group,
     };
-    st_foreach(GET_VM()->living_threads, thgroup_list_i, (st_data_t) & param);
+    st_foreach(GET_THREAD()->vm->living_threads, thgroup_list_i, (st_data_t) & param);
     return ary;
 }
 
@@ -1977,7 +1907,7 @@
     rb_define_singleton_method(cYarvThread, "new", yarv_thread_s_new, -2);
     rb_define_singleton_method(cYarvThread, "start", yarv_thread_s_new, -2);
     rb_define_singleton_method(cYarvThread, "fork", yarv_thread_s_new, -2);
-    rb_define_singleton_method(cYarvThread, "main", yarv_thread_s_main, 0);
+    rb_define_singleton_method(cYarvThread, "main", rb_thread_s_main, 0);
     rb_define_singleton_method(cYarvThread, "current", yarv_thread_s_current, 0);
     rb_define_singleton_method(cYarvThread, "stop", rb_thread_stop, 0);
     rb_define_singleton_method(cYarvThread, "kill", rb_thread_s_kill, 1);
@@ -2022,7 +1952,7 @@
     rb_define_method(cThGroup, "enclose", thgroup_enclose, 0);
     rb_define_method(cThGroup, "enclosed?", thgroup_enclosed_p, 0);
     rb_define_method(cThGroup, "add", thgroup_add, 1);
-    GET_VM()->thgroup_default = thgroup_default = rb_obj_alloc(cThGroup);
+    GET_THREAD()->vm->thgroup_default = thgroup_default = rb_obj_alloc(cThGroup);
     rb_define_const(cThGroup, "Default", thgroup_default);
 
     cMutex = rb_define_class("Mutex", rb_cObject);
@@ -2040,12 +1970,10 @@
 	/* main thread setting */
 	{
 	    /* acquire global interpreter lock */
-	    yarv_thread_lock_t *lp = &GET_VM()->global_interpreter_lock;
+	    yarv_thread_lock_t *lp = &GET_THREAD()->vm->global_interpreter_lock;
 	    native_mutex_initialize(lp);
 	    native_mutex_lock(lp);
 	}
     }
-    
-    native_mutex_initialize(&signal_thread_list_lock);
 }
 

Modified: trunk/thread_pthread.h
===================================================================
--- trunk/thread_pthread.h	2006-02-21 04:09:30 UTC (rev 455)
+++ trunk/thread_pthread.h	2006-02-21 12:09:54 UTC (rev 456)
@@ -11,7 +11,7 @@
 #define native_mutex_trylock pthread_mutex_trylock
 
 typedef struct native_thread_data_struct {
-    int dummy;
+    void *signal_thread_list;
 } native_thread_data_t;
 
 #endif /* THREAD_PTHREAD_H_INCLUDED */
@@ -30,6 +30,11 @@
 #define native_cleanup_pop  pthread_cleanup_pop
 #define native_thread_yield() sched_yield()
 
+static void yarv_add_signal_thread_list(yarv_thread_t *th);
+static void yarv_remove_signal_thread_list(yarv_thread_t *th);
+
+static yarv_thread_lock_t signal_thread_list_lock;
+
 static void
 null_func()
 {
@@ -39,6 +44,7 @@
 Init_native_thread()
 {
     GET_THREAD()->thread_id = pthread_self();
+    native_mutex_initialize(&signal_thread_list_lock);
     posix_signal(SIGVTALRM, null_func);
 }
 
@@ -128,6 +134,68 @@
     yarv_add_signal_thread_list(th);
 }
 
+struct yarv_signal_thread_list {
+    yarv_thread_t *th;
+    int need_signal;
+    struct yarv_signal_thread_list *prev;
+    struct yarv_signal_thread_list *next;
+};
+
+static struct yarv_signal_thread_list signal_thread_list_anchor = {
+    0, 0, 0, 0,
+};
+
+#define FGLOCK(lock, body) do { \
+    native_mutex_lock(lock); \
+    { \
+	body; \
+    } \
+    native_mutex_unlock(lock); \
+} while (0)
+
+static void
+yarv_add_signal_thread_list(yarv_thread_t *th)
+{
+    if (!th->native_thread_data.signal_thread_list) {
+	FGLOCK(&signal_thread_list_lock, {
+	    struct yarv_signal_thread_list *list =
+	      xmalloc(sizeof(struct yarv_signal_thread_list));
+	    list->th = th;
+
+	    list->prev = &signal_thread_list_anchor;
+	    list->next = signal_thread_list_anchor.next;
+	    if (list->next) {
+		list->next->prev = list;
+	    }
+	    signal_thread_list_anchor.next = list;
+	    th->native_thread_data.signal_thread_list = list;
+	});
+    }
+}
+
+static void
+yarv_remove_signal_thread_list(yarv_thread_t *th)
+{
+    if (th->native_thread_data.signal_thread_list) {
+	FGLOCK(&signal_thread_list_lock, {
+	    struct yarv_signal_thread_list *list =
+	      (struct yarv_signal_thread_list *)
+		th->native_thread_data.signal_thread_list;
+
+	    list->prev->next = list->next;
+	    if (list->next) {
+		list->next->prev = list->prev;
+	    }
+	    th->native_thread_data.signal_thread_list = 0;
+	    list->th = 0;
+	    xfree(list);
+	});
+    }
+    else {
+	/* */
+    }
+}
+
 static pthread_t time_thread;
 
 static void timer_function(void);
@@ -138,16 +206,26 @@
     while (system_working) {
 #ifdef HAVE_NANOSLEEP
 	struct timespec req, rem;
-
 	req.tv_sec = 0;
 	req.tv_nsec = 10 * 1000;	/* 10 ms */
 	nanosleep(&req, &rem);
 #else
 	struct timeval tv;
 	tv.tv_sec = 0;
-	tv.tv_usec = 10000;
+	tv.tv_usec = 10000;     	/* 10 ms */
 	select(0, NULL, NULL, NULL, &tv);
 #endif
+	if (signal_thread_list_anchor.next) {
+	    FGLOCK(&signal_thread_list_lock, {
+		struct yarv_signal_thread_list *list;
+		list = signal_thread_list_anchor.next;
+		while (list) {
+		    native_thread_send_interrupt_signal(list->th);
+		    list = list->next;
+		}
+	    });
+	}
+
 	timer_function();
     }
     return NULL;

Modified: trunk/thread_win32.h
===================================================================
--- trunk/thread_win32.h	2006-02-21 04:09:30 UTC (rev 455)
+++ trunk/thread_win32.h	2006-02-21 12:09:54 UTC (rev 456)
@@ -31,6 +31,7 @@
 #undef Sleep
 
 #define native_thread_yield() Sleep(0)
+#define yarv_remove_signal_thread_list(th)
 
 static void
 Init_native_thread()

Modified: trunk/vm_dump.c
===================================================================
--- trunk/vm_dump.c	2006-02-21 04:09:30 UTC (rev 455)
+++ trunk/vm_dump.c	2006-02-21 12:09:54 UTC (rev 456)
@@ -543,7 +543,7 @@
     yarv_thread_t *th = GET_THREAD();
     VALUE bt;
 
-    if (GET_VM()) {
+    if (GET_THREAD()->vm) {
 	int i;
 	SDR();
 	

Modified: trunk/yarv.h
===================================================================
--- trunk/yarv.h	2006-02-21 04:09:30 UTC (rev 455)
+++ trunk/yarv.h	2006-02-21 12:09:54 UTC (rev 456)
@@ -23,33 +23,24 @@
 
 
 #if YARV_THREAD_MODEL == 2
+
 extern yarv_thread_t *yarvCurrentThread;
 extern yarv_vm_t *theYarvVM;
 
 static inline VALUE
-yarv_get_current_running_vm_value(void)
-{
-    return theYarvVM->self;
-}
-
-static inline VALUE
 yarv_get_current_running_thread_value(void)
 {
     return yarvCurrentThread->self;
 }
 
-static inline yarv_vm_t *
-yarv_get_current_running_vm(void)
-{
-    return theYarvVM;
-}
-
 static inline yarv_thread_t *
 yarv_get_current_running_thread(void)
 {
     return yarvCurrentThread;
 }
 
+#define GET_THREAD() yarvCurrentThread
+
 static inline void
 yarv_set_current_running_thread_raw(yarv_thread_t *th)
 {
@@ -67,9 +58,6 @@
 #error "unsupported thread model"
 #endif
 
-#define GET_THREAD() yarv_get_current_running_thread()
-#define GET_VM()     yarv_get_current_running_vm()
-
 void rb_vm_change_state();
 
 VALUE th_invoke_yield(yarv_thread_t *th, int argc, VALUE *argv);

Modified: trunk/yarvcore.c
===================================================================
--- trunk/yarvcore.c	2006-02-21 04:09:30 UTC (rev 455)
+++ trunk/yarvcore.c	2006-02-21 12:09:54 UTC (rev 456)
@@ -558,8 +558,8 @@
 thread_free(void *ptr)
 {
     yarv_thread_t *th;
+    FREE_REPORT("-> thread");
 
-    FREE_REPORT("-> thread");
     if (ptr) {
 	th = ptr;
 	FREE_UNLESS_NULL(th->stack);
@@ -567,7 +567,13 @@
 	if (th->local_storage) {
 	    st_free_table(th->local_storage);
 	}
-	ruby_xfree(ptr);
+
+	if (th->vm->main_thread == th) {
+	    GC_INFO("main thread");
+	}
+	else {
+	    ruby_xfree(ptr);
+	}
     }
     FREE_REPORT("<- thread");
 }
@@ -668,7 +674,7 @@
 thread_init(VALUE self)
 {
     yarv_thread_t *th;
-    yarv_vm_t *vm = GET_VM();
+    yarv_vm_t *vm = GET_THREAD()->vm;
     GetThreadVal(self, th);
 
     th_init(th);
@@ -1229,8 +1235,9 @@
 
 	vm->main_thread = th;
 	vm->running_thread = th;
-
+	GET_THREAD()->vm = vm;
 	thread_free(GET_THREAD());
+	th->vm = vm;
 	yarv_set_current_running_thread(th);
 
 	th->machine_stack_start = rb_gc_stack_start;

Modified: trunk/yarvcore.h
===================================================================
--- trunk/yarvcore.h	2006-02-21 04:09:30 UTC (rev 455)
+++ trunk/yarvcore.h	2006-02-21 12:09:54 UTC (rev 456)
@@ -284,7 +284,6 @@
     VALUE self;
 
     yarv_thread_lock_t global_interpreter_lock;
-    unsigned long thread_critical;
 
     struct yarv_thread_struct *main_thread;
     struct yarv_thread_struct *running_thread;
@@ -400,8 +399,6 @@
     struct yarv_thread_struct *join_list_next;
     struct yarv_thread_struct *join_list_head;
     
-    void *signal_thread_list;
-
     VALUE first_proc;
     VALUE first_args;
 
@@ -550,31 +547,16 @@
 
 #include "yarv.h"
 
-#define GVL_LOCK_BEGIN() do { \
-  native_mutex_lock(&GET_VM()->global_interpreter_lock)
-
-#define GVL_LOCK_END() \
-  native_mutex_unlock(&GET_VM()->global_interpreter_lock); \
-} while(0)
-
 #define GVL_UNLOCK_BEGIN() do { \
   yarv_thread_t *_th_stored = GET_THREAD(); \
   yarv_save_machine_context(_th_stored); \
-  native_mutex_unlock(&GET_VM()->global_interpreter_lock)
+  native_mutex_unlock(&_th_stored->vm->global_interpreter_lock)
 
 #define GVL_UNLOCK_END() \
-  native_mutex_lock(&GET_VM()->global_interpreter_lock); \
+  native_mutex_lock(&_th_stored->vm->global_interpreter_lock); \
   yarv_set_current_running_thread(_th_stored); \
 } while(0)
 
-#define CSL_UNLOCK_BEGIN() do { \
-  int _thread_critical = GET_VM()->thread_critical; \
-  GET_VM()->thread_critical = 0
-
-#define CSL_UNLOCK_END() \
-  GET_VM()->thread_critical = _thread_critical; \
-} while(0)
-
 NOINLINE(void yarv_set_stack_end(VALUE **stack_end_p));
 NOINLINE(void yarv_save_machine_context(yarv_thread_t *));
 


-- 
ML: yarv-diff quickml.atdot.net
Info: http://www.atdot.net/~ko1/quickml

[前][次][番号順一覧][スレッド一覧][生データ]