Skip to content
This repository has been archived by the owner on Nov 18, 2021. It is now read-only.

Commit

Permalink
Integrate r28203 from MRI.
Browse files Browse the repository at this point in the history
  • Loading branch information
Brandon Mitchell committed Feb 14, 2011
1 parent 3721d05 commit a9eea5d
Show file tree
Hide file tree
Showing 3 changed files with 35 additions and 1 deletion.
9 changes: 9 additions & 0 deletions eval.c
Expand Up @@ -12609,6 +12609,8 @@ static struct timer_thread {
pthread_t thread; pthread_t thread;
} time_thread = {PTHREAD_COND_INITIALIZER, PTHREAD_MUTEX_INITIALIZER}; } time_thread = {PTHREAD_COND_INITIALIZER, PTHREAD_MUTEX_INITIALIZER};


static int timer_stopping;

#define safe_mutex_lock(lock) \ #define safe_mutex_lock(lock) \
pthread_mutex_lock(lock); \ pthread_mutex_lock(lock); \
pthread_cleanup_push((void (*)_((void *)))pthread_mutex_unlock, lock) pthread_cleanup_push((void (*)_((void *)))pthread_mutex_unlock, lock)
Expand All @@ -12633,6 +12635,9 @@ thread_timer(dummy)
#define WAIT_FOR_10MS() \ #define WAIT_FOR_10MS() \
pthread_cond_timedwait(&running->cond, &running->lock, get_ts(&to, PER_NANO/100)) pthread_cond_timedwait(&running->cond, &running->lock, get_ts(&to, PER_NANO/100))
while ((err = WAIT_FOR_10MS()) == EINTR || err == ETIMEDOUT) { while ((err = WAIT_FOR_10MS()) == EINTR || err == ETIMEDOUT) {
if (timer_stopping)
break;

if (!rb_thread_critical) { if (!rb_thread_critical) {
rb_thread_pending = 1; rb_thread_pending = 1;
if (rb_trap_immediate) { if (rb_trap_immediate) {
Expand Down Expand Up @@ -12660,7 +12665,9 @@ rb_thread_start_timer()
safe_mutex_lock(&time_thread.lock); safe_mutex_lock(&time_thread.lock);
if (pthread_create(&time_thread.thread, 0, thread_timer, args) == 0) { if (pthread_create(&time_thread.thread, 0, thread_timer, args) == 0) {
thread_init = 1; thread_init = 1;
#if !defined(__NetBSD__) && !defined(__APPLE__) && !defined(linux)
pthread_atfork(0, 0, rb_thread_stop_timer); pthread_atfork(0, 0, rb_thread_stop_timer);
#endif
pthread_cond_wait(&start, &time_thread.lock); pthread_cond_wait(&start, &time_thread.lock);
} }
pthread_cleanup_pop(1); pthread_cleanup_pop(1);
Expand All @@ -12671,10 +12678,12 @@ rb_thread_stop_timer()
{ {
if (!thread_init) return; if (!thread_init) return;
safe_mutex_lock(&time_thread.lock); safe_mutex_lock(&time_thread.lock);
timer_stopping = 1;
pthread_cond_signal(&time_thread.cond); pthread_cond_signal(&time_thread.cond);
thread_init = 0; thread_init = 0;
pthread_cleanup_pop(1); pthread_cleanup_pop(1);
pthread_join(time_thread.thread, NULL); pthread_join(time_thread.thread, NULL);
timer_stopping = 0;
} }
#elif defined(HAVE_SETITIMER) #elif defined(HAVE_SETITIMER)
static void static void
Expand Down
12 changes: 12 additions & 0 deletions io.c
Expand Up @@ -3248,6 +3248,9 @@ pipe_open(pstr, pname, mode)
} }


retry: retry:
#if defined(__NetBSD__) || defined(__APPLE__) || defined(linux)
rb_thread_stop_timer();
#endif
switch ((pid = fork())) { switch ((pid = fork())) {
case 0: /* child */ case 0: /* child */
if (modef & FMODE_READABLE) { if (modef & FMODE_READABLE) {
Expand Down Expand Up @@ -3275,11 +3278,17 @@ pipe_open(pstr, pname, mode)
ruby_sourcefile, ruby_sourceline, pname); ruby_sourcefile, ruby_sourceline, pname);
_exit(127); _exit(127);
} }
#if defined(__NetBSD__) || defined(__APPLE__) || defined(linux)
rb_thread_start_timer();
#endif
rb_io_synchronized(RFILE(orig_stdout)->fptr); rb_io_synchronized(RFILE(orig_stdout)->fptr);
rb_io_synchronized(RFILE(orig_stderr)->fptr); rb_io_synchronized(RFILE(orig_stderr)->fptr);
return Qnil; return Qnil;


case -1: /* fork failed */ case -1: /* fork failed */
#if defined(__NetBSD__) || defined(__APPLE__) || defined(linux)
rb_thread_start_timer();
#endif
if (errno == EAGAIN) { if (errno == EAGAIN) {
rb_thread_sleep(1); rb_thread_sleep(1);
goto retry; goto retry;
Expand All @@ -3300,6 +3309,9 @@ pipe_open(pstr, pname, mode)
break; break;


default: /* parent */ default: /* parent */
#if defined(__NetBSD__) || defined(__APPLE__) || defined(linux)
rb_thread_start_timer();
#endif
if (pid < 0) rb_sys_fail(pname); if (pid < 0) rb_sys_fail(pname);
else { else {
VALUE port = io_alloc(rb_cIO); VALUE port = io_alloc(rb_cIO);
Expand Down
15 changes: 14 additions & 1 deletion process.c
Expand Up @@ -1330,7 +1330,14 @@ rb_f_fork(obj)
fflush(stderr); fflush(stderr);
#endif #endif


switch (pid = fork()) { #if defined(__NetBSD__) || defined(__APPLE__) || defined(linux)
before_exec();
#endif
pid = fork();
#if defined(__NetBSD__) || defined(__APPLE__) || defined(linux)
after_exec();
#endif
switch (pid) {
case 0: case 0:
#ifdef linux #ifdef linux
after_exec(); after_exec();
Expand Down Expand Up @@ -1570,13 +1577,19 @@ rb_f_system(argc, argv)


chfunc = signal(SIGCHLD, SIG_DFL); chfunc = signal(SIGCHLD, SIG_DFL);
retry: retry:
#if defined(__NetBSD__) || defined(__APPLE__) || defined(linux)
before_exec();
#endif
pid = fork(); pid = fork();
if (pid == 0) { if (pid == 0) {
/* child process */ /* child process */
rb_thread_atfork(); rb_thread_atfork();
rb_protect(proc_exec_args, (VALUE)&earg, NULL); rb_protect(proc_exec_args, (VALUE)&earg, NULL);
_exit(127); _exit(127);
} }
#if defined(__NetBSD__) || defined(__APPLE__) || defined(linux)
after_exec();
#endif
if (pid < 0) { if (pid < 0) {
if (errno == EAGAIN) { if (errno == EAGAIN) {
rb_thread_sleep(1); rb_thread_sleep(1);
Expand Down

0 comments on commit a9eea5d

Please sign in to comment.