yarv-diff:381
From: ko1 atdot.net
Date: 3 Sep 2006 22:14:59 +0900
Subject: [yarv-diff:381] r548 - branches/parallel
Author: ko1
Date: 2006-09-03 22:14:57 +0900 (Sun, 03 Sep 2006)
New Revision: 548
Modified:
branches/parallel/ChangeLog
branches/parallel/class.c
branches/parallel/error.c
branches/parallel/eval.c
branches/parallel/eval_jump.h
branches/parallel/gc.c
branches/parallel/ruby.h
branches/parallel/signal.c
branches/parallel/thread.c
branches/parallel/thread_pthread.h
branches/parallel/vm.c
branches/parallel/vm_dump.c
branches/parallel/vm_macro.def
Log:
* class.c : add rb_define_method_ts API
* ruby.h : ditto
* vm_macro.def : check NODE_CFUNC->u3.cnt if lock is neede or not
* eval.c : remove unused rb_trap_restore_mask()
* eval_jump.h : ditto
* signal.c : ditto
* gc.c : return Qtrue if no need to run gc
* thread.c : fix some bugs
* thread_pthread.h : ditto
* vm.c : lock/unlock global lock on cfunc
* vm_dump.c : fix yarv_bug
* error.c : fix ruby_bug
Modified: branches/parallel/ChangeLog
===================================================================
--- branches/parallel/ChangeLog 2006-09-02 19:26:40 UTC (rev 547)
+++ branches/parallel/ChangeLog 2006-09-03 13:14:57 UTC (rev 548)
@@ -4,6 +4,33 @@
# from Mon, 03 May 2004 01:24:19 +0900
#
+2006-09-03(Sun) 21:53:37 +0900 Koichi Sasada <ko1 atdot.net>
+
+ * class.c : add rb_define_method_ts API
+
+ * ruby.h : ditto
+
+ * vm_macro.def : check NODE_CFUNC->u3.cnt if lock is neede or not
+
+ * eval.c : remove unused rb_trap_restore_mask()
+
+ * eval_jump.h : ditto
+
+ * signal.c : ditto
+
+ * gc.c : return Qtrue if no need to run gc
+
+ * thread.c : fix some bugs
+
+ * thread_pthread.h : ditto
+
+ * vm.c : lock/unlock global lock on cfunc
+
+ * vm_dump.c : fix yarv_bug
+
+ * error.c : fix ruby_bug
+
+
2006-09-03(Sun) 04:23:47 +0900 Koichi Sasada <ko1 atdot.net>
* thread.c : add cancel blocking state feature
Modified: branches/parallel/class.c
===================================================================
--- branches/parallel/class.c 2006-09-02 19:26:40 UTC (rev 547)
+++ branches/parallel/class.c 2006-09-03 13:14:57 UTC (rev 548)
@@ -769,6 +769,14 @@
}
void
+rb_define_method_ts(VALUE klass, const char *name, VALUE (*func)(ANYARGS), int argc)
+{
+ NODE *node = NEW_CFUNC(func, argc);
+ node->u3.cnt = 1;
+ rb_add_method(klass, rb_intern(name), node, NOEX_PUBLIC);
+}
+
+void
rb_define_protected_method(VALUE klass, const char *name, VALUE (*func)(ANYARGS), int argc)
{
rb_add_method(klass, rb_intern(name), NEW_CFUNC(func, argc), NOEX_PROTECTED);
Modified: branches/parallel/error.c
===================================================================
--- branches/parallel/error.c 2006-09-02 19:26:40 UTC (rev 547)
+++ branches/parallel/error.c 2006-09-03 13:14:57 UTC (rev 548)
@@ -156,17 +156,17 @@
char buf[BUFSIZ];
va_list args;
FILE *out = stderr;
- int len = err_position(buf, BUFSIZ);
+ int len = 0;//err_position(buf, BUFSIZ);
if (fwrite(buf, 1, len, out) == len ||
fwrite(buf, 1, len, (out = stdout)) == len) {
- yarv_bug();
- fputs("[BUG] ", out);
- va_start(args, fmt);
- vfprintf(out, fmt, args);
- va_end(args);
- fprintf(out, "\nruby %s (%s) [%s]\n\n",
- ruby_version, ruby_release_date, ruby_platform);
+ yarv_bug();
+ fputs("[BUG] ", out);
+ va_start(args, fmt);
+ vfprintf(out, fmt, args);
+ va_end(args);
+ fprintf(out, "\nruby %s (%s) [%s]\n\n",
+ ruby_version, ruby_release_date, ruby_platform);
}
abort();
}
Modified: branches/parallel/eval.c
===================================================================
--- branches/parallel/eval.c 2006-09-02 19:26:40 UTC (rev 547)
+++ branches/parallel/eval.c 2006-09-03 13:14:57 UTC (rev 548)
@@ -952,7 +952,6 @@
}
}
- rb_trap_restore_mask();
if (tag != TAG_FATAL) {
// EXEC_EVENT_HOOK(RUBY_EVENT_RAISE ...)
}
Modified: branches/parallel/eval_jump.h
===================================================================
--- branches/parallel/eval_jump.h 2006-09-02 19:26:40 UTC (rev 547)
+++ branches/parallel/eval_jump.h 2006-09-03 13:14:57 UTC (rev 548)
@@ -39,7 +39,6 @@
rb_name_error(SYM2ID(tag), "uncaught throw `%s'",
rb_id2name(SYM2ID(tag)));
}
- rb_trap_restore_mask();
th->errinfo = tag;
JUMP_TAG(TAG_THROW);
Modified: branches/parallel/gc.c
===================================================================
--- branches/parallel/gc.c 2006-09-02 19:26:40 UTC (rev 547)
+++ branches/parallel/gc.c 2006-09-03 13:14:57 UTC (rev 548)
@@ -1353,6 +1353,9 @@
if (freelist == 0) {
r = garbage_collect_thread_unsafe();
}
+ else {
+ r = Qtrue;
+ }
rb_thread_gc_barrier_end(th);
if (locked) {
Modified: branches/parallel/ruby.h
===================================================================
--- branches/parallel/ruby.h 2006-09-02 19:26:40 UTC (rev 547)
+++ branches/parallel/ruby.h 2006-09-03 13:14:57 UTC (rev 548)
@@ -541,6 +541,7 @@
#define RUBY_METHOD_FUNC(func) ((VALUE (*)(ANYARGS))func)
void rb_define_method(VALUE,const char*,VALUE(*)(ANYARGS),int);
+void rb_define_method_ts(VALUE,const char*,VALUE(*)(ANYARGS),int);
void rb_define_module_function(VALUE,const char*,VALUE(*)(ANYARGS),int);
void rb_define_global_function(const char*,VALUE(*)(ANYARGS),int);
Modified: branches/parallel/signal.c
===================================================================
--- branches/parallel/signal.c 2006-09-02 19:26:40 UTC (rev 547)
+++ branches/parallel/signal.c 2006-09-03 13:14:57 UTC (rev 548)
@@ -416,8 +416,8 @@
sigfillset(&mask);
sigdelset(&mask, SIGVTALRM);
sigdelset(&mask, SIGSEGV);
- pthread_sigmask(SIG_SETMASK, &mask, NULL);
- trap_last_mask = mask;
+ sigdelset(&mask, SIGPROF);
+ pthread_sigmask(SIG_SETMASK, &mask, &trap_last_mask);
#endif
}
@@ -458,10 +458,11 @@
#endif
#ifdef SIGSEGV
-static int segv_received = 0;
static RETSIGTYPE
sigsegv(int sig)
{
+ static int segv_received = 0;
+
if (segv_received) {
fprintf(stderr, "SEGV recieved in SEGV handler\n");
exit(1);
@@ -714,18 +715,6 @@
}
#endif
-void
-rb_trap_restore_mask(void)
-{
-#ifndef _WIN32
-# ifdef HAVE_SIGPROCMASK
- sigprocmask(SIG_SETMASK, &trap_last_mask, NULL);
-# else
- sigsetmask(trap_last_mask);
-# endif
-#endif
-}
-
/*
* call-seq:
* Signal.trap( signal, proc ) => obj
Modified: branches/parallel/thread.c
===================================================================
--- branches/parallel/thread.c 2006-09-02 19:26:40 UTC (rev 547)
+++ branches/parallel/thread.c 2006-09-03 13:14:57 UTC (rev 548)
@@ -41,7 +41,7 @@
#include "eval_intern.h"
#include "vm.h"
-#define THREAD_DEBUG 0
+#define THREAD_DEBUG 1
static void sleep_for_polling();
static void sleep_timeval(yarv_thread_t *th, struct timeval time);
@@ -52,12 +52,12 @@
static int rb_thread_dead(yarv_thread_t *th);
void rb_signal_exec(yarv_thread_t *th, int sig);
-void rb_disable_interrupt();
+void rb_disable_interrupt(void);
NOINLINE(void yarv_set_stack_end(VALUE **stack_end_p));
-static VALUE eKillSignal = INT2FIX(0);
-static VALUE eTerminateSignal = INT2FIX(1);
+static const VALUE eKillSignal = INT2FIX(0);
+static const VALUE eTerminateSignal = INT2FIX(1);
static int system_working = 1;
@@ -143,20 +143,24 @@
rb_thread_global_lock_acquire(yarv_thread_t *th)
{
yarv_vm_t *vm = th->vm;
- if (vm->lock_owner_thread == th || rb_thread_alone()) {
- thread_debug("rb_thread_global_lock_acquire: no need (%s)\n",
- vm->lock_owner_thread == th ? "already own" : "alone");
+ if (vm->lock_owner_thread == th) {
+ thread_debug("rb_thread_global_lock_acquire: no need (already have)\n");
return 0;
}
- yarv_save_machine_context(th);
- thread_debug("rb_thread_global_lock_acquire: try acquire (%p) --> \n",
- vm->lock_owner_thread);
- if (native_mutex_lock(&vm->global_interpreter_lock) != 0) {
- rb_bug("native_mutex_lock return non-zero");
+ else if (rb_thread_alone()) {
+ thread_debug("rb_thread_global_lock_acquire: no need (alone)\n");
+ return 1;
}
- vm->lock_owner_thread = th;
- thread_debug("rb_thread_global_lock_acquire: <-- done\n");
- return 1;
+ else {
+ thread_debug("rb_thread_global_lock_acquire: try acquire (%p) --> \n",
+ vm->lock_owner_thread);
+ if (native_mutex_lock(&vm->global_interpreter_lock) != 0) {
+ rb_bug("native_mutex_lock return non-zero");
+ }
+ vm->lock_owner_thread = th;
+ thread_debug("rb_thread_global_lock_acquire: <-- done\n");
+ return 1;
+ }
}
int
@@ -229,6 +233,7 @@
thread_debug("rb_thread_gc_barrier_stop: waiting -> %d\n",
vm->num_wait_threads);
{
+ yarv_save_machine_context(th);
pthread_cond_signal(&vm->gc_barrier_owner_cond);
pthread_cond_wait(&vm->gc_barrier_waits_cond,
&vm->global_interpreter_lock);
@@ -373,7 +378,6 @@
yarv_thread_t *th = th_ptr;
th->status = THREAD_KILLED;
th->machine_stack_start = th->machine_stack_end = 0;
- st_delete_wrap(th->vm->living_threads, th->self);
if (th->vm->interrupt_gc_flag) {
pthread_cond_signal(&th->vm->gc_barrier_owner_cond);
Modified: branches/parallel/thread_pthread.h
===================================================================
--- branches/parallel/thread_pthread.h 2006-09-02 19:26:40 UTC (rev 547)
+++ branches/parallel/thread_pthread.h 2006-09-03 13:14:57 UTC (rev 548)
@@ -39,12 +39,18 @@
#define FGLOCK_RANGE(lock, body) \
{ FGLOCK(lock); { body; } FGUNLOCK(lock); }
-#define GL_LOCK_RANGE(th_, body) { \
- rb_thread_global_lock_acquire(th_); \
+#define GL_LOCK_RANGE(th_, body) do { \
+ int __locked = rb_thread_global_lock_acquire(th_); \
{ body; } ; \
- rb_thread_global_lock_release(th_); \
-}
+ if (__locked) rb_thread_global_lock_release(th_); \
+} while (0)
+#define GL_UNLOCK_RANGE(th_, body) do { \
+ int __freeed = rb_thread_global_lock_release(th_); \
+ { body; } ;\
+ if (__freeed) rb_thread_global_lock_acquire(th_); \
+} while (0)
+
#endif /* THREAD_PTHREAD_H_INCLUDED */
@@ -52,12 +58,12 @@
#ifdef THREAD_SYSTEM_DEPENDENT_IMPLEMENTATION
-#define native_mutex_initialize(lock) do { \
- pthread_mutex_t _lock = PTHREAD_MUTEX_INITIALIZER; \
- ((*lock) = _lock); \
-} while (0)
-
void
+native_mutex_initialize(pthread_mutex_t *lock)
+{
+ pthread_mutex_init(lock, 0);
+}
+void
native_fglock_init(yarv_thread_fglock_t *lock)
{
native_fg_init(lock, 0);
Modified: branches/parallel/vm.c
===================================================================
--- branches/parallel/vm.c 2006-09-02 19:26:40 UTC (rev 547)
+++ branches/parallel/vm.c 2006-09-03 13:14:57 UTC (rev 548)
@@ -475,7 +475,16 @@
cfp->method_id = id;
cfp->method_klass = klass;
- val = call_cfunc(body->nd_cfnc, recv, body->nd_argc, argc, argv);
+ if (body->u3.cnt == 0) {
+ GL_LOCK_RANGE(th, {
+ val = call_cfunc(body->nd_cfnc, recv, body->nd_argc, argc, argv);
+ });
+ }
+ else {
+ GL_UNLOCK_RANGE(th, {
+ val = call_cfunc(body->nd_cfnc, recv, body->nd_argc, argc, argv);
+ });
+ }
if (reg_cfp != th->cfp + 1) {
SDR2(reg_cfp);
@@ -567,7 +576,9 @@
self, (VALUE)block->dfp,
0, th->cfp->sp, block->lfp, 1);
- val = (*ifunc->nd_cfnc) (arg, ifunc->nd_tval, Qnil);
+ GL_LOCK_RANGE(th, {
+ val = (*ifunc->nd_cfnc) (arg, ifunc->nd_tval, Qnil);
+ });
th->cfp++;
return val;
@@ -1550,9 +1561,10 @@
int state;
VALUE result, err;
VALUE initial = 0;
+ int locked;
/* free lock */
- rb_thread_global_lock_release(th);
+ locked = rb_thread_global_lock_release(th);
/* eval body */
@@ -1753,6 +1765,8 @@
finish_vme:
TH_POP_TAG();
- rb_thread_global_lock_acquire(th);
+ if (locked) {
+ rb_thread_global_lock_acquire(th);
+ }
return result;
}
Modified: branches/parallel/vm_dump.c
===================================================================
--- branches/parallel/vm_dump.c 2006-09-02 19:26:40 UTC (rev 547)
+++ branches/parallel/vm_dump.c 2006-09-03 13:14:57 UTC (rev 548)
@@ -566,10 +566,10 @@
void
yarv_bug()
{
- yarv_thread_t *th = GET_THREAD();
+ yarv_thread_t *th = GET_VM()->main_thread;
VALUE bt;
- if (GET_THREAD()->vm) {
+ if (th->vm) {
int i;
SDR();
Modified: branches/parallel/vm_macro.def
===================================================================
--- branches/parallel/vm_macro.def 2006-09-02 19:26:40 UTC (rev 547)
+++ branches/parallel/vm_macro.def 2006-09-03 13:14:57 UTC (rev 548)
@@ -61,10 +61,14 @@
reg_cfp->sp -= num + 1;
- GL_LOCK_RANGE(
- th,
+ if (mn->u3.cnt == 0) {
+ GL_LOCK_RANGE(th, {
+ val = call_cfunc(mn->nd_cfnc, recv, mn->nd_argc, num, reg_cfp->sp + 1);
+ });
+ }
+ else {
val = call_cfunc(mn->nd_cfnc, recv, mn->nd_argc, num, reg_cfp->sp + 1);
- );
+ }
if (reg_cfp != th->cfp + 1) {
SDR2(reg_cfp);
--
ML: yarv-diff quickml.atdot.net
Info: http://www.atdot.net/~ko1/quickml