summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authornobu <nobu@b2dd03c8-39d4-4d8f-98ff-823fe69b080e>2008-11-08 15:31:05 +0000
committernobu <nobu@b2dd03c8-39d4-4d8f-98ff-823fe69b080e>2008-11-08 15:31:05 +0000
commit641f43de973d51a7d463b067833d4a71706d6c5c (patch)
tree555a72d40d2a2645020a675fc085b716dd097f2b
parentb2390fb1cc3f38ca4516394034c8680eeb01a64c (diff)
* thread_pthread.c (thread_timer): checks working flags again.
git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@20160 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
-rw-r--r--ChangeLog4
-rw-r--r--thread.c4
-rw-r--r--thread_pthread.c13
-rw-r--r--thread_win32.c11
4 files changed, 25 insertions, 7 deletions
diff --git a/ChangeLog b/ChangeLog
index 86fa6fad15..02ecef3622 100644
--- a/ChangeLog
+++ b/ChangeLog
@@ -1,3 +1,7 @@
+Sun Nov 9 00:30:52 2008 Nobuyoshi Nakada <nobu@ruby-lang.org>
+
+ * thread_pthread.c (thread_timer): checks working flags again.
+
Sun Nov 9 00:02:01 2008 Takeyuki FUJIOKA <xibbar@ruby-lang.org>
* lib/cgi/session/pstore.rb: fix indentation.
diff --git a/thread.c b/thread.c
index ca47419644..f6bcc9801f 100644
--- a/thread.c
+++ b/thread.c
@@ -75,6 +75,7 @@ void rb_thread_stop_timer_thread(void);
static const VALUE eKillSignal = INT2FIX(0);
static const VALUE eTerminateSignal = INT2FIX(1);
+static volatile int system_working = 1;
inline static void
st_delete_wrap(st_table *table, st_data_t key)
@@ -2355,8 +2356,7 @@ timer_thread_function(void *arg)
void
rb_thread_stop_timer_thread(void)
{
- if (timer_thread_id) {
- native_stop_timer_thread();
+ if (timer_thread_id && native_stop_timer_thread()) {
native_thread_join(timer_thread_id);
timer_thread_id = 0;
}
diff --git a/thread_pthread.c b/thread_pthread.c
index 5fc335b304..7ddfcea7b0 100644
--- a/thread_pthread.c
+++ b/thread_pthread.c
@@ -679,9 +679,9 @@ thread_timer(void *dummy)
int err;
native_mutex_lock(&timer_thread_lock);
- native_cond_signal(&timer_thread_cond);
+ native_cond_broadcast(&timer_thread_cond);
#define WAIT_FOR_10MS() native_cond_timedwait(&timer_thread_cond, &timer_thread_lock, get_ts(&ts, PER_NANO/100))
- while ((err = WAIT_FOR_10MS()) != 0 && err != EINTR) {
+ while (system_working > 0 && (err = WAIT_FOR_10MS()) != 0 && err != EINTR) {
if (err != ETIMEDOUT) {
rb_bug("thread_timer/timedwait: %d", err);
}
@@ -729,12 +729,17 @@ rb_thread_create_timer_thread(void)
rb_disable_interrupt(); /* only timer thread recieve signal */
}
-static void
+static int
native_stop_timer_thread(void)
{
+ int stopped;
native_mutex_lock(&timer_thread_lock);
- native_cond_signal(&timer_thread_cond);
+ stopped = --system_working <= 0;
+ if (stopped) {
+ native_cond_signal(&timer_thread_cond);
+ }
native_mutex_unlock(&timer_thread_lock);
+ return stopped;
}
#endif /* THREAD_SYSTEM_DEPENDENT_IMPLEMENTATION */
diff --git a/thread_win32.c b/thread_win32.c
index feba5ecfcc..0befbff4ae 100644
--- a/thread_win32.c
+++ b/thread_win32.c
@@ -558,6 +558,15 @@ rb_thread_create_timer_thread(void)
}
}
-#define native_stop_timer_thread() (CloseHandle(timer_thread_lock), timer_thread_lock = 0)
+static int
+native_stop_timer_thread(void)
+{
+ int stopped = --system_working <= 0;
+ if (stopped) {
+ CloseHandle(timer_thread_lock);
+ timer_thread_lock = 0;
+ }
+ return stopped;
+}
#endif /* THREAD_SYSTEM_DEPENDENT_IMPLEMENTATION */