Skip to content
Browse files

Okay. So, maybe this works.

  • Loading branch information...
1 parent 811d0ca commit 038589224a2d91b6eb4833954c0d3fb29e586a83 Brandon Mitchell committed Aug 2, 2011
Showing with 27 additions and 28 deletions.
  1. +27 −28 eval.c
View
55 eval.c
@@ -11428,15 +11428,14 @@ rb_thread_schedule()
again:
max = -1;
+ FD_ZERO(&curr->scratch_readfds);
+ FD_ZERO(&curr->scratch_writefds);
+ FD_ZERO(&curr->scratch_exceptfds);
+ bzero(&curr->scratch_delay_tv, sizeof(struct timeval));
delay = DELAY_INFTY;
now = -1.0;
FOREACH_THREAD_FROM(curr, th) {
- FD_ZERO(&th->scratch_readfds);
- FD_ZERO(&th->scratch_writefds);
- FD_ZERO(&th->scratch_exceptfds);
- bzero(&th->scratch_delay_tv, sizeof(struct timeval));
-
th->wait_for &= ~WAIT_DONE;
if (!found && th->status <= THREAD_RUNNABLE) {
found = 1;
@@ -11450,14 +11449,14 @@ rb_thread_schedule()
}
}
if (th->wait_for & WAIT_FD) {
- FD_SET(th->fd, &th->scratch_readfds);
+ FD_SET(th->fd, &curr->scratch_readfds);
if (max < th->fd) max = th->fd;
need_select = 1;
}
if (th->wait_for & WAIT_SELECT) {
- copy_fds(&th->scratch_readfds, &th->readfds, th->fd);
- copy_fds(&th->scratch_writefds, &th->writefds, th->fd);
- copy_fds(&th->scratch_exceptfds, &th->exceptfds, th->fd);
+ copy_fds(&curr->scratch_readfds, &th->readfds, th->fd);
+ copy_fds(&curr->scratch_writefds, &th->writefds, th->fd);
+ copy_fds(&curr->scratch_exceptfds, &th->exceptfds, th->fd);
if (max < th->fd) max = th->fd;
need_select = 1;
if (th->wait_for & WAIT_TIME) {
@@ -11497,18 +11496,18 @@ rb_thread_schedule()
if (found) {
th->scratch_delay_tv.tv_sec = 0;
th->scratch_delay_tv.tv_usec = 0;
- delay_ptr = &th->scratch_delay_tv;
+ delay_ptr = &curr->scratch_delay_tv;
}
else if (delay == DELAY_INFTY) {
delay_ptr = 0;
}
else {
th->scratch_delay_tv.tv_sec = delay;
th->scratch_delay_tv.tv_usec = (delay - (double)th->scratch_delay_tv.tv_sec)*1e6;
- delay_ptr = &th->scratch_delay_tv;
+ delay_ptr = &curr->scratch_delay_tv;
}
- n = select(max+1, &th->scratch_readfds, &th->scratch_writefds, &th->scratch_exceptfds, delay_ptr);
+ n = select(max+1, &curr->scratch_readfds, &curr->scratch_writefds, &curr->scratch_exceptfds, delay_ptr);
if (n < 0) {
int e = errno;
@@ -11522,9 +11521,9 @@ rb_thread_schedule()
int fd;
int dummy;
for (fd = 0; fd <= max; fd++) {
- if ((FD_ISSET(fd, &th->scratch_readfds) ||
- FD_ISSET(fd, &th->scratch_writefds) ||
- FD_ISSET(fd, &th->scratch_exceptfds)) &&
+ if ((FD_ISSET(fd, &curr->scratch_readfds) ||
+ FD_ISSET(fd, &curr->scratch_writefds) ||
+ FD_ISSET(fd, &curr->scratch_exceptfds)) &&
#ifndef _WIN32
fcntl(fd, F_GETFD, &dummy) == -1 &&
#else
@@ -11564,9 +11563,9 @@ rb_thread_schedule()
if (th->wait_for & WAIT_SELECT) {
int v = 0;
- v |= find_bad_fds(&th->scratch_readfds, &th->readfds, th->fd);
- v |= find_bad_fds(&th->scratch_writefds, &th->writefds, th->fd);
- v |= find_bad_fds(&th->scratch_exceptfds, &th->exceptfds, th->fd);
+ v |= find_bad_fds(&curr->scratch_readfds, &th->readfds, th->fd);
+ v |= find_bad_fds(&curr->scratch_writefds, &th->writefds, th->fd);
+ v |= find_bad_fds(&curr->scratch_exceptfds, &th->exceptfds, th->fd);
if (v) {
th->select_value = n;
n = max;
@@ -11585,9 +11584,9 @@ rb_thread_schedule()
th->wait_for = 0;
th->select_value = 0;
found = 1;
- intersect_fds(&th->scratch_readfds, &th->readfds, max);
- intersect_fds(&th->scratch_writefds, &th->writefds, max);
- intersect_fds(&th->scratch_exceptfds, &th->exceptfds, max);
+ intersect_fds(&curr->scratch_readfds, &th->readfds, max);
+ intersect_fds(&curr->scratch_writefds, &th->writefds, max);
+ intersect_fds(&curr->scratch_exceptfds, &th->exceptfds, max);
}
}
END_FOREACH_FROM(curr, th);
@@ -11601,14 +11600,14 @@ rb_thread_schedule()
* threads which don't run next should not be changed.
*/
FOREACH_THREAD_FROM(curr, th) {
- if ((th->wait_for&WAIT_FD) && FD_ISSET(th->fd, &th->scratch_readfds)) {
+ if ((th->wait_for&WAIT_FD) && FD_ISSET(th->fd, &curr->scratch_readfds)) {
th->wait_for |= WAIT_DONE;
found = 1;
}
if ((th->wait_for&WAIT_SELECT) &&
- (match_fds(&th->scratch_readfds, &th->readfds, max) ||
- match_fds(&th->scratch_writefds, &th->writefds, max) ||
- match_fds(&th->scratch_exceptfds, &th->exceptfds, max))) {
+ (match_fds(&curr->scratch_readfds, &th->readfds, max) ||
+ match_fds(&curr->scratch_writefds, &th->writefds, max) ||
+ match_fds(&curr->scratch_exceptfds, &th->exceptfds, max))) {
th->wait_for |= WAIT_DONE;
found = 1;
}
@@ -11640,9 +11639,9 @@ rb_thread_schedule()
next->fd = 0;
}
else { /* next->wait_for&WAIT_SELECT */
- n = intersect_fds(&th->scratch_readfds, &next->readfds, max) +
- intersect_fds(&th->scratch_writefds, &next->writefds, max) +
- intersect_fds(&th->scratch_exceptfds, &next->exceptfds, max);
+ n = intersect_fds(&curr->scratch_readfds, &next->readfds, max) +
+ intersect_fds(&curr->scratch_writefds, &next->writefds, max) +
+ intersect_fds(&curr->scratch_exceptfds, &next->exceptfds, max);
next->select_value = n;
}
next->wait_for = 0;

0 comments on commit 0385892

Please sign in to comment.
Something went wrong with that request. Please try again.