summaryrefslogtreecommitdiffstats
path: root/eval.c
diff options
context:
space:
mode:
authorshyouhei <shyouhei@b2dd03c8-39d4-4d8f-98ff-823fe69b080e>2009-02-21 15:18:42 +0000
committershyouhei <shyouhei@b2dd03c8-39d4-4d8f-98ff-823fe69b080e>2009-02-21 15:18:42 +0000
commitd05d9aef4ed56513a65c6c139c8d3d087475c164 (patch)
treeff0dc3d5735d8af0c42c314010f6cc0a214f0717 /eval.c
parent958730224b6d18d59b065d359d96c11aecc2bb1b (diff)
downloadruby-d05d9aef4ed56513a65c6c139c8d3d087475c164.tar.gz
ruby-d05d9aef4ed56513a65c6c139c8d3d087475c164.tar.xz
ruby-d05d9aef4ed56513a65c6c139c8d3d087475c164.zip
merge revision(s) 21165:
* eval.c (rb_thread_schedule): Don't change status of threads which don't run next even if select notify readability/writability. [ruby-core:20446] git-svn-id: http://svn.ruby-lang.org/repos/ruby/branches/ruby_1_8_6@22476 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
Diffstat (limited to 'eval.c')
-rw-r--r--eval.c43
1 files changed, 26 insertions, 17 deletions
diff --git a/eval.c b/eval.c
index 8e037f633..3f8c32b59 100644
--- a/eval.c
+++ b/eval.c
@@ -10676,6 +10676,7 @@ rb_thread_schedule()
rb_thread_t next; /* OK */
rb_thread_t th;
rb_thread_t curr;
+ rb_thread_t th_found = 0;
int found = 0;
fd_set readfds;
@@ -10821,28 +10822,22 @@ rb_thread_schedule()
if (n > 0) {
now = -1.0;
/* Some descriptors are ready.
- Make the corresponding threads runnable. */
+ * Choose a thread which may run next.
+ * Don't change the status of threads which don't run next.
+ */
FOREACH_THREAD_FROM(curr, th) {
if ((th->wait_for&WAIT_FD) && FD_ISSET(th->fd, &readfds)) {
- /* Wake up only one thread per fd. */
- FD_CLR(th->fd, &readfds);
- th->status = THREAD_RUNNABLE;
- th->fd = 0;
- th->wait_for = 0;
+ th_found = th;
found = 1;
+ break;
}
if ((th->wait_for&WAIT_SELECT) &&
(match_fds(&readfds, &th->readfds, max) ||
match_fds(&writefds, &th->writefds, max) ||
match_fds(&exceptfds, &th->exceptfds, max))) {
- /* Wake up only one thread per fd. */
- th->status = THREAD_RUNNABLE;
- th->wait_for = 0;
- n = intersect_fds(&readfds, &th->readfds, max) +
- intersect_fds(&writefds, &th->writefds, max) +
- intersect_fds(&exceptfds, &th->exceptfds, max);
- th->select_value = n;
- found = 1;
+ th_found = th;
+ found = 1;
+ break;
}
}
END_FOREACH_FROM(curr, th);
@@ -10858,9 +10853,23 @@ rb_thread_schedule()
next = th;
break;
}
- if (th->status == THREAD_RUNNABLE && th->stk_ptr) {
- if (!next || next->priority < th->priority)
- next = th;
+ if ((th->status == THREAD_RUNNABLE || th == th_found) && th->stk_ptr) {
+ if (!next || next->priority < th->priority) {
+ if (th == th_found) {
+ th_found->status = THREAD_RUNNABLE;
+ th_found->wait_for = 0;
+ if (th->wait_for&WAIT_FD) {
+ th_found->fd = 0;
+ }
+ else { /* th->wait_for&WAIT_SELECT */
+ n = intersect_fds(&readfds, &th_found->readfds, max) +
+ intersect_fds(&writefds, &th_found->writefds, max) +
+ intersect_fds(&exceptfds, &th_found->exceptfds, max);
+ th_found->select_value = n;
+ }
+ }
+ next = th;
+ }
}
}
END_FOREACH_FROM(curr, th);