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