yarv-diff:415
From: ko1 atdot.net
Date: 12 Dec 2006 13:19:01 +0900
Subject: [yarv-diff:415] r583 - in trunk: . rb test/ruby
Author: ko1
Date: 2006-12-12 13:19:00 +0900 (Tue, 12 Dec 2006)
New Revision: 583
Modified:
trunk/ChangeLog
trunk/eval_thread.c
trunk/process.c
trunk/rb/insns2vm.rb
trunk/signal.c
trunk/test/ruby/test_signal.rb
trunk/thread.c
trunk/thread_pthread.ci
trunk/thread_win32.ci
trunk/vm.h
trunk/yarvcore.c
trunk/yarvcore.h
Log:
* rb/insns2vm.rb : add PREFETCH() statement
* vm.h : ditto
* yarvcore.h : fix LIKELY(x) and
remove main_thread_val field from yarv_vm_t
* yarvcore.c : ditto
* thread.c : support fork
* eval_thread.c : ditto
* process.c : ditto
* signal.c : ditto
* test/ruby/test_signal.rb :
* thread_pthread.ci : rename timer thread functions
* thread_win32.ci : ditto
Modified: trunk/ChangeLog
===================================================================
--- trunk/ChangeLog 2006-12-06 09:35:51 UTC (rev 582)
+++ trunk/ChangeLog 2006-12-12 04:19:00 UTC (rev 583)
@@ -4,6 +4,32 @@
# from Mon, 03 May 2004 01:24:19 +0900
#
+2006-12-12(Tue) 13:13:32 +0900 Koichi Sasada <ko1 atdot.net>
+
+ * rb/insns2vm.rb : add PREFETCH() statement
+
+ * vm.h : ditto
+
+ * yarvcore.h : fix LIKELY(x) and
+ remove main_thread_val field from yarv_vm_t
+
+ * yarvcore.c : ditto
+
+ * thread.c : support fork
+
+ * eval_thread.c : ditto
+
+ * process.c : ditto
+
+ * signal.c : ditto
+
+ * test/ruby/test_signal.rb :
+
+ * thread_pthread.ci : rename timer thread functions
+
+ * thread_win32.ci : ditto
+
+
2006-11-10(Fri) 21:29:13 +0900 Koichi Sasada <ko1 atdot.net>
* compile.c : fix to compile arguments
Modified: trunk/eval_thread.c
===================================================================
--- trunk/eval_thread.c 2006-12-06 09:35:51 UTC (rev 582)
+++ trunk/eval_thread.c 2006-12-12 04:19:00 UTC (rev 583)
@@ -464,15 +464,7 @@
* threading libraries.
*/
-/***/
-void
-rb_thread_atfork(void)
-{
- // TODO
-}
-
-
/*
* Document-class: Continuation
*
Modified: trunk/process.c
===================================================================
--- trunk/process.c 2006-12-06 09:35:51 UTC (rev 582)
+++ trunk/process.c 2006-12-12 04:19:00 UTC (rev 583)
@@ -605,7 +605,7 @@
break;
}
if (!pid_tbl)
- pid_tbl = st_init_numtable();
+ pid_tbl = st_init_numtable();
st_insert(pid_tbl, pid, (st_data_t)st);
if (!rb_thread_alone()) rb_thread_schedule();
}
@@ -891,13 +891,8 @@
char *strtok();
#endif
-#ifdef HAVE_SETITIMER
-#define before_exec()
-#define after_exec()
-#else
-#define before_exec()
-#define after_exec()
-#endif
+#define before_exec() rb_enable_interrupt()
+#define after_exec() rb_disable_interrupt()
extern char *dln_find_exe(const char *fname, const char *path);
@@ -1352,6 +1347,7 @@
_exit(127);
#endif
}
+ rb_thread_reset_timer_thread();
}
#ifdef FD_CLOEXEC
else if (chfunc) {
@@ -1522,9 +1518,6 @@
{
int status;
VALUE prog;
-#if defined HAVE_FORK
- struct rb_exec_arg earg;
-#endif
prog = rb_check_argv(argc, argv);
@@ -1533,11 +1526,14 @@
prog = *argv++;
}
#if defined HAVE_FORK
- earg.argc = argc;
- earg.argv = argv;
- earg.prog = prog ? RSTRING_PTR(prog) : 0;
- status = rb_fork(&status, (int (*)(void*))rb_exec, &earg);
- if (prog && argc) argv[0] = prog;
+ {
+ struct rb_exec_arg earg;
+ earg.argc = argc;
+ earg.argv = argv;
+ earg.prog = prog ? RSTRING_PTR(prog) : 0;
+ status = rb_fork(&status, (int (*)(void*))rb_exec, &earg);
+ if (prog && argc) argv[0] = prog;
+ }
#elif defined HAVE_SPAWNV
if (!argc) {
status = proc_spawn(RSTRING_PTR(prog));
@@ -1593,7 +1589,7 @@
status = rb_spawn(argc, argv);
#if defined(HAVE_FORK) || defined(HAVE_SPAWNV)
if (status > 0) {
- rb_syswait(status);
+ rb_syswait(status);
}
#endif
#ifdef SIGCHLD
Modified: trunk/rb/insns2vm.rb
===================================================================
--- trunk/rb/insns2vm.rb 2006-12-06 09:35:51 UTC (rev 582)
+++ trunk/rb/insns2vm.rb 2006-12-12 04:19:00 UTC (rev 583)
@@ -738,6 +738,7 @@
ret += " DEBUG_ENTER_INSN(\"#{insn.name}\");\n"
ret += " /* management */\n" if $verbose
ret += " ADD_PC(1+#{@opn});\n"
+ ret += " PREFETCH(GET_PC());\n"
ret += " POPN(#{@popn});\n" if @popn > 0
ret += " #define CURRENT_INSN_#{insn.name} 1\n"
ret += " #define INSN_IS_SC() #{insn.sc ? 0 : 1}\n"
Modified: trunk/signal.c
===================================================================
--- trunk/signal.c 2006-12-06 09:35:51 UTC (rev 582)
+++ trunk/signal.c 2006-12-12 04:19:00 UTC (rev 583)
@@ -417,15 +417,16 @@
sigdelset(&mask, SIGVTALRM);
sigdelset(&mask, SIGSEGV);
pthread_sigmask(SIG_SETMASK, &mask, NULL);
- trap_last_mask = mask;
#endif
}
-static void
+void
rb_enable_interrupt(void)
{
#ifndef _WIN32
- pthread_sigmask(SIG_SETMASK, &trap_last_mask, NULL);
+ sigset_t mask;
+ sigemptyset(&mask);
+ pthread_sigmask(SIG_SETMASK, &mask, NULL);
#endif
}
Modified: trunk/test/ruby/test_signal.rb
===================================================================
--- trunk/test/ruby/test_signal.rb 2006-12-06 09:35:51 UTC (rev 582)
+++ trunk/test/ruby/test_signal.rb 2006-12-12 04:19:00 UTC (rev 583)
@@ -34,8 +34,6 @@
def test_exit_action
return unless have_fork? # snip this test
- # assert(false, "test_exit_action doesn't work on cygwin") if /cygwin/ =~ RUBY_PLATFORM
- assert(false, "This tests doesn't work on YARV.")
begin
r, w = IO.pipe
r0, w0 = IO.pipe
Modified: trunk/thread.c
===================================================================
--- trunk/thread.c 2006-12-06 09:35:51 UTC (rev 582)
+++ trunk/thread.c 2006-12-12 04:19:00 UTC (rev 583)
@@ -967,7 +967,7 @@
VALUE
rb_thread_main(void)
{
- return GET_THREAD()->vm->main_thread_val;
+ return GET_THREAD()->vm->main_thread->self;
}
static VALUE
@@ -1582,7 +1582,7 @@
int rb_get_next_signal(yarv_vm_t *vm);
static void
-timer_function(void)
+timer_thread_function(void)
{
yarv_vm_t *vm = GET_VM(); /* TODO: fix me for Multi-VM */
vm->running_thread->interrupt_flag = 1;
@@ -1595,6 +1595,20 @@
}
}
+/***/
+
+void
+rb_thread_atfork(void)
+{
+ yarv_thread_t *th = GET_THREAD();
+ yarv_vm_t *vm = th->vm;
+ vm->main_thread = th;
+
+ st_free_table(vm->living_threads);
+ vm->living_threads = st_init_numtable();
+ st_insert(vm->living_threads, th->self, (st_data_t) th->thread_id);
+}
+
/*
* for tests
*/
@@ -1612,7 +1626,6 @@
}
-
struct thgroup {
int enclosed;
VALUE group;
@@ -2011,7 +2024,6 @@
}
}
- make_timer_thread();
- rb_disable_interrupt(); /* only timer thread recieve signal */
+ rb_thread_create_timer_thread();
}
Modified: trunk/thread_pthread.ci
===================================================================
--- trunk/thread_pthread.ci 2006-12-06 09:35:51 UTC (rev 582)
+++ trunk/thread_pthread.ci 2006-12-12 04:19:00 UTC (rev 583)
@@ -71,7 +71,7 @@
return 0;
}
-static void make_timer_thread();
+void rb_thread_create_control_thread(void);
static pthread_mutex_t thread_cache_lock = PTHREAD_MUTEX_INITIALIZER;
@@ -281,7 +281,7 @@
thread_debug("native_sleep done\n");
}
-void
+static void
native_thread_interrupt(yarv_thread_t *th)
{
yarv_add_signal_thread_list(th);
@@ -367,10 +367,9 @@
}
}
-static pthread_t time_thread;
+static pthread_t timer_thread_id;
+static void timer_thread_function(void);
-static void timer_function(void);
-
static void *
thread_timer(void *dummy)
{
@@ -386,7 +385,6 @@
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;
@@ -397,23 +395,37 @@
}
});
}
- timer_function();
+ timer_thread_function();
}
return NULL;
}
static void
-make_timer_thread()
+rb_thread_create_timer_thread(void)
{
- if (!time_thread) {
+ rb_enable_interrupt();
+
+ if (!timer_thread_id) {
size_t stack_size = PTHREAD_STACK_MIN;
pthread_attr_t attr;
-
+ int err;
+
pthread_attr_init(&attr);
pthread_attr_setstacksize(&attr, stack_size);
pthread_attr_setdetachstate(&attr, PTHREAD_CREATE_DETACHED);
- pthread_create(&time_thread, &attr, thread_timer, 0);
+ err = pthread_create(&timer_thread_id, &attr, thread_timer, 0);
+ if (err != 0) {
+ rb_bug("rb_thread_create_timer_thread: return non-zero (%d)", err);
+ }
}
+ rb_disable_interrupt(); /* only timer thread recieve signal */
}
+void
+rb_thread_reset_timer_thread(void)
+{
+ timer_thread_id = 0;
+ rb_thread_create_timer_thread();
+}
+
#endif /* THREAD_SYSTEM_DEPENDENT_IMPLEMENTATION */
Modified: trunk/thread_win32.ci
===================================================================
--- trunk/thread_win32.ci 2006-12-06 09:35:51 UTC (rev 582)
+++ trunk/thread_win32.ci 2006-12-12 04:19:00 UTC (rev 583)
@@ -273,7 +273,7 @@
SetEvent(th->native_thread_data.interrupt_event);
}
-static void timer_function(void);
+static void timer_thread_function(void);
static HANDLE timer_thread_handle = 0;
@@ -283,14 +283,14 @@
thread_debug("timer_thread\n");
while (system_working) {
Sleep(WIN32_WAIT_TIMEOUT);
- timer_function();
+ timer_thread_function();
}
thread_debug("timer killed\n");
return 0;
}
-static void
-make_timer_thread()
+void
+rb_thread_create_timer_thread(void)
{
if (timer_thread_handle == 0) {
timer_thread_handle = w32_create_thread(1024, timer_thread_func, 0);
Modified: trunk/vm.h
===================================================================
--- trunk/vm.h 2006-12-06 09:35:51 UTC (rev 582)
+++ trunk/vm.h 2006-12-12 04:19:00 UTC (rev 583)
@@ -46,14 +46,18 @@
#define USAGE_ANALYSIS_INSN(insn) /* none */
#define USAGE_ANALYSIS_OPERAND(insn, n, op) /* none */
#define USAGE_ANALYSIS_REGISTER(reg, s) /* none */
+#endif
+#ifdef __GCC__
+/* TODO: machine dependent prefetch instruction */
+#define PREFETCH(pc)
+#else
+#define PREFETCH(pc)
#endif
#if VMDEBUG > 0
-
#define debugs printf
-
-#define DEBUG_ENTER_INSN(insn) \
+#define DEBUG_ENTER_INSN(insn) \
debug_print_pre(th, GET_CFP());
#if OPT_STACK_CACHING
@@ -62,7 +66,7 @@
#define SC_REGS()
#endif
-#define DEBUG_END_INSN() \
+#define DEBUG_END_INSN() \
debug_print_post(th, GET_CFP() SC_REGS());
#else
Modified: trunk/yarvcore.c
===================================================================
--- trunk/yarvcore.c 2006-12-06 09:35:51 UTC (rev 582)
+++ trunk/yarvcore.c 2006-12-12 04:19:00 UTC (rev 583)
@@ -1012,6 +1012,8 @@
{
/* create vm object */
VALUE vmval = vm_alloc(cYarvVM);
+ VALUE thval;
+
yarv_vm_t *vm;
yarv_thread_t *th;
vm = theYarvVM;
@@ -1025,8 +1027,8 @@
rb_ary_push(yarvVMArray, vm->self);
/* create main thread */
- vm->main_thread_val = yarv_thread_alloc(cYarvThread);
- GetThreadPtr(vm->main_thread_val, th);
+ thval = yarv_thread_alloc(cYarvThread);
+ GetThreadPtr(thval, th);
vm->main_thread = th;
vm->running_thread = th;
Modified: trunk/yarvcore.h
===================================================================
--- trunk/yarvcore.h 2006-12-06 09:35:51 UTC (rev 582)
+++ trunk/yarvcore.h 2006-12-12 04:19:00 UTC (rev 583)
@@ -76,13 +76,13 @@
#endif /* OPT_CALL_THREADED_CODE */
/* likely */
-#ifdef __GCC__
+#if __GNUC__ >= 3
#define LIKELY(x) (__builtin_expect((x), 1))
#define UNLIKELY(x) (__builtin_expect((x), 0))
-#else /* __GCC__ */
-#define LIKELY(x) ((x) == 1)
-#define UNLIKELY(x) ((x) == 0)
-#endif /* __GCC__ */
+#else /* __GNUC__ >= 3 */
+#define LIKELY(x) (x)
+#define UNLIKELY(x) (x)
+#endif /* __GNUC__ >= 3 */
#define YARVDEBUG 0
#define CPDEBUG 0
@@ -315,7 +315,6 @@
struct yarv_thread_struct *main_thread;
struct yarv_thread_struct *running_thread;
- VALUE main_thread_val;
st_table *living_threads;
VALUE thgroup_default;
--
ML: yarv-diff quickml.atdot.net
Info: http://www.atdot.net/~ko1/quickml