Skip to content
This repository has been archived by the owner on May 4, 2018. It is now read-only.

Commit

Permalink
Ugly hack to avoid loop starvation
Browse files Browse the repository at this point in the history
  • Loading branch information
piscisaureus committed Aug 26, 2011
1 parent 39aac4a commit 48f827f
Show file tree
Hide file tree
Showing 2 changed files with 7 additions and 1 deletion.
5 changes: 4 additions & 1 deletion src/win/core.c
Expand Up @@ -156,6 +156,7 @@ static void uv_poll_ex(int block) {


#define UV_LOOP(poll) \
int mb; \
while (LOOP->refs > 0) { \
uv_update_time(); \
uv_process_timers(); \
Expand All @@ -168,9 +169,11 @@ static void uv_poll_ex(int block) {
/* Completely flush all pending reqs and endgames. */ \
/* We do even when we just called the idle callbacks because those may */ \
/* have closed handles or started requests that short-circuited. */ \
mb = 100; \
while (LOOP->pending_reqs_tail || LOOP->endgame_handles) { \
uv_process_endgames(); \
uv_process_reqs(); \
if (--mb <= 0) break; \
} \
\
if (LOOP->refs <= 0) { \
Expand All @@ -179,7 +182,7 @@ static void uv_poll_ex(int block) {
\
uv_prepare_invoke(); \
\
poll(LOOP->idle_handles == NULL && LOOP->refs > 0); \
poll(LOOP->idle_handles == NULL && LOOP->pending_reqs_tail == NULL && LOOP->refs > 0); \
\
uv_check_invoke(); \
}
Expand Down
3 changes: 3 additions & 0 deletions src/win/req.c
Expand Up @@ -91,6 +91,7 @@ static uv_req_t* uv_remove_pending_req() {

void uv_process_reqs() {
uv_req_t* req;
int mb = 100;

while (req = uv_remove_pending_req()) {
switch (req->type) {
Expand Down Expand Up @@ -153,5 +154,7 @@ void uv_process_reqs() {
default:
assert(0);
}

if (mb-- <= 0) break;
}
}

0 comments on commit 48f827f

Please sign in to comment.