mirror of
https://github.com/ruby/ruby.git
synced 2022-11-09 12:17:21 -05:00
* thread.c (rb_thread_stop_timer_thread(), rb_thread_reset_timer_thread(),
rb_thread_start_timer_thread()): added. * thread_pthread.ci: add a native_thread_join() and move rb_thread_reset_timer_thread() definition to thread.c. * thread_win32.ci: ditto * process.c: fix before_exec(), after_exec() to stop timer thread (and restart timer thread if exec failed). and fix to reset timer thread information when forked child process starts (to fix [ruby-core:09822]). git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@11509 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
This commit is contained in:
parent
4e4eec7016
commit
84f8da1157
5 changed files with 61 additions and 22 deletions
15
ChangeLog
15
ChangeLog
|
@ -1,3 +1,18 @@
|
|||
Sun Jan 7 18:36:05 2007 Koichi Sasada <ko1@atdot.net>
|
||||
|
||||
* thread.c (rb_thread_stop_timer_thread(), rb_thread_reset_timer_thread(),
|
||||
rb_thread_start_timer_thread()): added.
|
||||
|
||||
* thread_pthread.ci: add a native_thread_join() and move
|
||||
rb_thread_reset_timer_thread() definition to thread.c.
|
||||
|
||||
* thread_win32.ci: ditto
|
||||
|
||||
* process.c: fix before_exec(), after_exec() to stop timer thread
|
||||
(and restart timer thread if exec failed). and fix to reset
|
||||
timer thread information when forked child process starts
|
||||
(to fix [ruby-core:09822]).
|
||||
|
||||
Sun Jan 7 18:28:17 2007 Koichi Sasada <ko1@atdot.net>
|
||||
|
||||
* common.mk: add a "compare" rule and fix MATZRUBY variable
|
||||
|
|
|
@ -891,8 +891,10 @@ proc_detach(VALUE obj, VALUE pid)
|
|||
char *strtok();
|
||||
#endif
|
||||
|
||||
#define before_exec() rb_enable_interrupt()
|
||||
#define after_exec() rb_disable_interrupt()
|
||||
#define before_exec() \
|
||||
(rb_enable_interrupt(), rb_thread_stop_timer_thread())
|
||||
#define after_exec() \
|
||||
(rb_thread_start_timer_thread(), rb_disable_interrupt())
|
||||
|
||||
extern char *dln_find_exe(const char *fname, const char *path);
|
||||
|
||||
|
@ -1332,6 +1334,7 @@ rb_fork(int *status, int (*chfunc)(void*), void *charg)
|
|||
}
|
||||
}
|
||||
if (!pid) {
|
||||
rb_thread_reset_timer_thread();
|
||||
if (chfunc) {
|
||||
#ifdef FD_CLOEXEC
|
||||
close(ep[0]);
|
||||
|
@ -1347,7 +1350,7 @@ rb_fork(int *status, int (*chfunc)(void*), void *charg)
|
|||
_exit(127);
|
||||
#endif
|
||||
}
|
||||
rb_thread_reset_timer_thread();
|
||||
rb_thread_start_timer_thread();
|
||||
}
|
||||
#ifdef FD_CLOEXEC
|
||||
else if (chfunc) {
|
||||
|
|
23
thread.c
23
thread.c
|
@ -65,7 +65,7 @@ NOINLINE(void yarv_set_stack_end(VALUE **stack_end_p));
|
|||
|
||||
static VALUE eKillSignal = INT2FIX(0);
|
||||
static VALUE eTerminateSignal = INT2FIX(1);
|
||||
static int system_working = 1;
|
||||
static volatile int system_working = 1;
|
||||
|
||||
inline static void
|
||||
st_delete_wrap(st_table * table, VALUE key)
|
||||
|
@ -1602,6 +1602,27 @@ timer_thread_function(void)
|
|||
}
|
||||
}
|
||||
|
||||
void
|
||||
rb_thread_stop_timer_thread(void)
|
||||
{
|
||||
if (timer_thread_id) {
|
||||
system_working = 0;
|
||||
native_thread_join(timer_thread_id);
|
||||
}
|
||||
}
|
||||
|
||||
void
|
||||
rb_thread_reset_timer_thread(void)
|
||||
{
|
||||
timer_thread_id = 0;
|
||||
}
|
||||
|
||||
void
|
||||
rb_thread_start_timer_thread(void)
|
||||
{
|
||||
rb_thread_create_timer_thread();
|
||||
}
|
||||
|
||||
/***/
|
||||
|
||||
void
|
||||
|
|
|
@ -205,6 +205,15 @@ native_thread_create(yarv_thread_t *th)
|
|||
return err;
|
||||
}
|
||||
|
||||
static void
|
||||
native_thread_join(pthread_t th)
|
||||
{
|
||||
int err = pthread_join(th, 0);
|
||||
if (err) {
|
||||
rb_raise(rb_eThreadError, "native_thread_join() failed (%d)", err);
|
||||
}
|
||||
}
|
||||
|
||||
static void
|
||||
native_thread_apply_priority(yarv_thread_t *th)
|
||||
{
|
||||
|
@ -430,7 +439,6 @@ rb_thread_create_timer_thread(void)
|
|||
#ifdef PTHREAD_STACK_MIN
|
||||
pthread_attr_setstacksize(&attr, PTHREAD_STACK_MIN);
|
||||
#endif
|
||||
pthread_attr_setdetachstate(&attr, PTHREAD_CREATE_DETACHED);
|
||||
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);
|
||||
|
@ -439,11 +447,4 @@ rb_thread_create_timer_thread(void)
|
|||
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 */
|
||||
|
|
|
@ -259,6 +259,12 @@ native_thread_create(yarv_thread_t *th)
|
|||
return 0;
|
||||
}
|
||||
|
||||
static void
|
||||
native_thread_join(HANDLE th)
|
||||
{
|
||||
w32_wait_event(th, 0, 0);
|
||||
}
|
||||
|
||||
static void
|
||||
native_thread_apply_priority(yarv_thread_t *th)
|
||||
{
|
||||
|
@ -285,7 +291,7 @@ native_thread_interrupt(yarv_thread_t *th)
|
|||
|
||||
static void timer_thread_function(void);
|
||||
|
||||
static HANDLE timer_thread_handle = 0;
|
||||
static HANDLE timer_thread_id = 0;
|
||||
|
||||
static unsigned int _stdcall
|
||||
timer_thread_func(void *dummy)
|
||||
|
@ -302,16 +308,9 @@ timer_thread_func(void *dummy)
|
|||
void
|
||||
rb_thread_create_timer_thread(void)
|
||||
{
|
||||
if (timer_thread_handle == 0) {
|
||||
timer_thread_handle = w32_create_thread(1024, timer_thread_func, 0);
|
||||
if (timer_thread_id == 0) {
|
||||
timer_thread_id = w32_create_thread(1024, timer_thread_func, 0);
|
||||
}
|
||||
}
|
||||
|
||||
void
|
||||
rb_thread_reset_timer_thread(void)
|
||||
{
|
||||
timer_thread_handle = 0;
|
||||
rb_thread_create_timer_thread();
|
||||
}
|
||||
|
||||
#endif /* THREAD_SYSTEM_DEPENDENT_IMPLEMENTATION */
|
||||
|
|
Loading…
Add table
Reference in a new issue