summaryrefslogtreecommitdiff
path: root/thread_pthread.c
diff options
context:
space:
mode:
authorko1 <ko1@b2dd03c8-39d4-4d8f-98ff-823fe69b080e>2011-06-28 21:17:29 +0000
committerko1 <ko1@b2dd03c8-39d4-4d8f-98ff-823fe69b080e>2011-06-28 21:17:29 +0000
commitc22126755cd89f2b8aa309df8908d839e588a3bd (patch)
tree6a8f60739dffae50ce16a690eda77eaa56cdd550 /thread_pthread.c
parent58018f1f2d41ec28203439496537106e6b08c377 (diff)
* 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 <normalperson@yhbt.net>. 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
Diffstat (limited to 'thread_pthread.c')
-rw-r--r--thread_pthread.c18
1 files changed, 11 insertions, 7 deletions
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;
}