summaryrefslogtreecommitdiff
path: root/eval.c
diff options
context:
space:
mode:
authorshyouhei <shyouhei@b2dd03c8-39d4-4d8f-98ff-823fe69b080e>2009-11-17 07:32:15 +0000
committershyouhei <shyouhei@b2dd03c8-39d4-4d8f-98ff-823fe69b080e>2009-11-17 07:32:15 +0000
commit8162d69dda2e584cdaa1bd50eebce1648454ebe4 (patch)
tree70196d82abb8e70f3872dd54cafe3d16fa4dea74 /eval.c
parenteaa8ca6b78be62f74ccb79f91631c07e82e5bb2a (diff)
merge revision(s) 24958,24979:
* eval.c (rb_thread_start_timer): start to catch SIGVTALRM together with timer thread. [ruby-core:25606] * eval.c (rb_thread_atfork): stop timer thread. * eval.c (rb_thread_start_0, rb_thread_start_1): should call star timer after added new thread to thread list. [ruby-core:25613] git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/branches/ruby_1_8_7@25819 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
Diffstat (limited to 'eval.c')
-rw-r--r--eval.c32
1 files changed, 20 insertions, 12 deletions
diff --git a/eval.c b/eval.c
index 37c460da80..ba15931e69 100644
--- a/eval.c
+++ b/eval.c
@@ -12244,6 +12244,12 @@ rb_thread_alloc(klass)
static int thread_init;
+#if defined(POSIX_SIGNAL)
+#define CATCH_VTALRM() posix_signal(SIGVTALRM, catch_timer)
+#else
+#define CATCH_VTALRM() signal(SIGVTALRM, catch_timer)
+#endif
+
#if defined(_THREAD_SAFE)
static void
catch_timer(sig)
@@ -12327,6 +12333,8 @@ rb_thread_start_timer()
static pthread_cond_t start = PTHREAD_COND_INITIALIZER;
if (thread_init) return;
+ if (rb_thread_alone()) return;
+ CATCH_VTALRM();
args[0] = &time_thread;
args[1] = &start;
safe_mutex_lock(&time_thread.lock);
@@ -12368,6 +12376,8 @@ rb_thread_start_timer()
struct itimerval tval;
if (thread_init) return;
+ if (rb_thread_alone()) return;
+ CATCH_VTALRM();
tval.it_interval.tv_sec = 0;
tval.it_interval.tv_usec = 10000;
tval.it_value = tval.it_interval;
@@ -12391,6 +12401,14 @@ rb_thread_stop_timer()
int rb_thread_tick = THREAD_TICK;
#endif
+#if defined(HAVE_SETITIMER) || defined(_THREAD_SAFE)
+#define START_TIMER() (thread_init ? (void)0 : rb_thread_start_timer())
+#define STOP_TIMER() (rb_thread_stop_timer())
+#else
+#define START_TIMER() ((void)0)
+#define STOP_TIMER() ((void)0)
+#endif
+
static VALUE
rb_thread_start_0(fn, arg, th)
VALUE (*fn)();
@@ -12408,18 +12426,6 @@ rb_thread_start_0(fn, arg, th)
"can't start a new thread (frozen ThreadGroup)");
}
- if (!thread_init) {
-#if defined(HAVE_SETITIMER) || defined(_THREAD_SAFE)
-#if defined(POSIX_SIGNAL)
- posix_signal(SIGVTALRM, catch_timer);
-#else
- signal(SIGVTALRM, catch_timer);
-#endif
-
- rb_thread_start_timer();
-#endif
- }
-
if (THREAD_SAVE_CONTEXT(curr_thread)) {
return thread;
}
@@ -12442,6 +12448,7 @@ rb_thread_start_0(fn, arg, th)
th->priority = curr_thread->priority;
th->thgroup = curr_thread->thgroup;
}
+ START_TIMER();
PUSH_TAG(PROT_THREAD);
if ((state = EXEC_TAG()) == 0) {
@@ -13167,6 +13174,7 @@ rb_thread_atfork()
main_thread = curr_thread;
curr_thread->next = curr_thread;
curr_thread->prev = curr_thread;
+ STOP_TIMER();
}