thread_pthread.c: timer_thread_pipe struct

* thread_pthread.c (timer_thread_pipe): aggregate timer thread
  pipe stuff into a struct.

git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@45907 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
This commit is contained in:
nobu 2014-05-10 14:48:58 +00:00
Родитель 779ce6b00e
Коммит 3385f6a0d4
1 изменённых файлов: 23 добавлений и 18 удалений

Просмотреть файл

@ -1218,9 +1218,14 @@ static int check_signal_thread_list(void) { return 0; }
#define TIME_QUANTUM_USEC (100 * 1000)
#if USE_SLEEPY_TIMER_THREAD
static int timer_thread_pipe[2] = {-1, -1};
static int timer_thread_pipe_low[2] = {-1, -1}; /* low priority */
static int timer_thread_pipe_owner_process;
static struct {
int normal[2];
int low[2];
int owner_process;
} timer_thread_pipe = {
{-1, -1},
{-1, -1}, /* low priority */
};
/* only use signal-safe system calls here */
static void
@ -1229,7 +1234,7 @@ rb_thread_wakeup_timer_thread_fd(int fd)
ssize_t result;
/* already opened */
if (timer_thread_pipe_owner_process == getpid()) {
if (timer_thread_pipe.owner_process == getpid()) {
const char *buff = "!";
retry:
if ((result = write(fd, buff, 1)) <= 0) {
@ -1254,13 +1259,13 @@ rb_thread_wakeup_timer_thread_fd(int fd)
void
rb_thread_wakeup_timer_thread(void)
{
rb_thread_wakeup_timer_thread_fd(timer_thread_pipe[1]);
rb_thread_wakeup_timer_thread_fd(timer_thread_pipe.normal[1]);
}
static void
rb_thread_wakeup_timer_thread_low(void)
{
rb_thread_wakeup_timer_thread_fd(timer_thread_pipe_low[1]);
rb_thread_wakeup_timer_thread_fd(timer_thread_pipe.low[1]);
}
/* VM-dependent API is not available for this function */
@ -1341,15 +1346,15 @@ setup_communication_pipe_internal(int pipes[2])
static void
setup_communication_pipe(void)
{
if (timer_thread_pipe_owner_process == getpid()) {
if (timer_thread_pipe.owner_process == getpid()) {
/* already set up. */
return;
}
setup_communication_pipe_internal(timer_thread_pipe);
setup_communication_pipe_internal(timer_thread_pipe_low);
setup_communication_pipe_internal(timer_thread_pipe.normal);
setup_communication_pipe_internal(timer_thread_pipe.low);
/* validate pipe on this process */
timer_thread_pipe_owner_process = getpid();
timer_thread_pipe.owner_process = getpid();
}
/**
@ -1365,9 +1370,9 @@ timer_thread_sleep(rb_global_vm_lock_t* gvl)
int need_polling;
struct pollfd pollfds[2];
pollfds[0].fd = timer_thread_pipe[0];
pollfds[0].fd = timer_thread_pipe.normal[0];
pollfds[0].events = POLLIN;
pollfds[1].fd = timer_thread_pipe_low[0];
pollfds[1].fd = timer_thread_pipe.low[0];
pollfds[1].events = POLLIN;
need_polling = check_signal_thread_list();
@ -1385,8 +1390,8 @@ timer_thread_sleep(rb_global_vm_lock_t* gvl)
/* maybe timeout */
}
else if (result > 0) {
consume_communication_pipe(timer_thread_pipe[0]);
consume_communication_pipe(timer_thread_pipe_low[0]);
consume_communication_pipe(timer_thread_pipe.normal[0]);
consume_communication_pipe(timer_thread_pipe.low[0]);
}
else { /* result < 0 */
int e = errno;
@ -1598,10 +1603,10 @@ int
rb_reserved_fd_p(int fd)
{
#if USE_SLEEPY_TIMER_THREAD
if (fd == timer_thread_pipe[0] ||
fd == timer_thread_pipe[1] ||
fd == timer_thread_pipe_low[0] ||
fd == timer_thread_pipe_low[1]) {
if (fd == timer_thread_pipe.normal[0] ||
fd == timer_thread_pipe.normal[1] ||
fd == timer_thread_pipe.low[0] ||
fd == timer_thread_pipe.low[1]) {
return 1;
}
else {