Created
May 16, 2020 14:52
-
-
Save korzio/02022ff5455cca29b5232aa1cda8d7fd to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
int uv_run(uv_loop_t* loop, uv_run_mode mode) { | |
int timeout; | |
int r; | |
int ran_pending; | |
r = uv__loop_alive(loop); | |
if (!r) | |
uv__update_time(loop); | |
while (r != 0 && loop->stop_flag == 0) { | |
uv__update_time(loop); | |
uv__run_timers(loop); | |
ran_pending = uv__run_pending(loop); | |
uv__run_idle(loop); | |
uv__run_prepare(loop); | |
timeout = 0; | |
if ((mode == UV_RUN_ONCE && !ran_pending) || mode == UV_RUN_DEFAULT) | |
timeout = uv_backend_timeout(loop); | |
uv__io_poll(loop, timeout); | |
uv__run_check(loop); | |
uv__run_closing_handles(loop); | |
if (mode == UV_RUN_ONCE) { | |
/* UV_RUN_ONCE implies forward progress: at least one callback must have | |
* been invoked when it returns. uv__io_poll() can return without doing | |
* I/O (meaning: no callbacks) when its timeout expires - which means we | |
* have pending timers that satisfy the forward progress constraint. | |
* | |
* UV_RUN_NOWAIT makes no guarantees about progress so it's omitted from | |
* the check. | |
*/ | |
uv__update_time(loop); | |
uv__run_timers(loop); | |
} | |
r = uv__loop_alive(loop); | |
if (mode == UV_RUN_ONCE || mode == UV_RUN_NOWAIT) | |
break; | |
} | |
/* The if statement lets gcc compile it to a conditional store. Avoids | |
* dirtying a cache line. | |
*/ | |
if (loop->stop_flag != 0) | |
loop->stop_flag = 0; | |
return r; | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment