From c22126755cd89f2b8aa309df8908d839e588a3bd Mon Sep 17 00:00:00 2001 From: ko1 Date: Tue, 28 Jun 2011 21:17:29 +0000 Subject: * error.c (rb_async_bug_errno): async-safe bug report function. In timer thread, signal handler shoul use it. The patch is contributed by Eric Wong . Refs: [ruby-core:37644] and [ruby-core:37647] * thread_pthread.c: use rb_async_bug_errno(). And replace all fprintf() to write(). * internal.h (rb_async_bug_errno): add decl. of above func. git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@32274 b2dd03c8-39d4-4d8f-98ff-823fe69b080e --- thread_pthread.c | 18 +++++++++++------- 1 file changed, 11 insertions(+), 7 deletions(-) (limited to 'thread_pthread.c') diff --git a/thread_pthread.c b/thread_pthread.c index e78c10fb46..420a3f4db5 100644 --- a/thread_pthread.c +++ b/thread_pthread.c @@ -990,6 +990,9 @@ static int timer_thread_pipe_owner_process; #define TT_DEBUG 0 +#define WRITE_CONST(fd, str) write((fd),(str),sizeof(str)-1); + +/* only use signal-safe system calls here */ void rb_thread_wakeup_timer_thread(void) { @@ -1008,16 +1011,17 @@ rb_thread_wakeup_timer_thread(void) #endif break; default: - rb_bug_errno("rb_thread_wakeup_timer_thread - write", errno); + rb_async_bug_errno("rb_thread_wakeup_timer_thread - write", errno); } } - if (TT_DEBUG) fprintf(stderr, "rb_thread_wakeup_timer_thread: write\n"); + if (TT_DEBUG) WRITE_CONST(2, "rb_thread_wakeup_timer_thread: write\n"); } else { /* ignore wakeup */ } } +/* VM-dependent API is not available for this function */ static void consume_communication_pipe(void) { @@ -1032,7 +1036,7 @@ consume_communication_pipe(void) switch (errno) { case EINTR: goto retry; default: - rb_bug_errno("consume_communication_pipe: read", errno); + rb_async_bug_errno("consume_communication_pipe: read\n", errno); } } } @@ -1061,7 +1065,7 @@ thread_timer(void *p) int result; struct timeval timeout; - if (TT_DEBUG) fprintf(stderr, "start timer thread\n"); + if (TT_DEBUG) WRITE_CONST(2, "start timer thread\n"); while (system_working > 0) { fd_set rfds; @@ -1069,7 +1073,7 @@ thread_timer(void *p) /* timer function */ ping_signal_thread_list(); timer_thread_function(0); - if (TT_DEBUG) fprintf(stderr, "tick\n"); + if (TT_DEBUG) WRITE_CONST(2, "tick\n"); /* wait */ FD_ZERO(&rfds); @@ -1098,12 +1102,12 @@ thread_timer(void *p) /* interrupted. ignore */ } else { - rb_bug_errno("thread_timer: select", errno); + rb_async_bug_errno("thread_timer: select", errno); } } } - if (TT_DEBUG) fprintf(stderr, "finish timer thread\n"); + if (TT_DEBUG) WRITE_CONST(2, "finish timer thread\n"); return NULL; } -- cgit v1.2.3