summaryrefslogtreecommitdiffstats
path: root/Utilities/cmlibuv/src/unix/kqueue.c
diff options
context:
space:
mode:
authorBrad King <brad.king@kitware.com>2020-09-24 19:15:38 (GMT)
committerKitware Robot <kwrobot@kitware.com>2020-09-24 19:16:28 (GMT)
commitc98ec731f90eb0180c89108b7d2e42263b66d1ed (patch)
tree2d67994bbea44ba6712e6dcb637438f6dbfb0ac6 /Utilities/cmlibuv/src/unix/kqueue.c
parent0436f70f80de4a56313b9da0668ac6674078b2d1 (diff)
parent7a0506bafe387bfff441c0159b9a3d58f68db177 (diff)
downloadCMake-c98ec731f90eb0180c89108b7d2e42263b66d1ed.zip
CMake-c98ec731f90eb0180c89108b7d2e42263b66d1ed.tar.gz
CMake-c98ec731f90eb0180c89108b7d2e42263b66d1ed.tar.bz2
Merge topic 'update-libuv'
7a0506bafe libuv: Suppress conversion warning on Windows 2269ad6a0a libuv: Add fs_copy stub to cmake-bootstrap.c e21325c2c6 Merge branch 'upstream-libuv' into update-libuv c1463f959f libuv 2020-09-22 (ed5b42d5) Acked-by: Kitware Robot <kwrobot@kitware.com> Merge-request: !5259
Diffstat (limited to 'Utilities/cmlibuv/src/unix/kqueue.c')
-rw-r--r--Utilities/cmlibuv/src/unix/kqueue.c55
1 files changed, 48 insertions, 7 deletions
diff --git a/Utilities/cmlibuv/src/unix/kqueue.c b/Utilities/cmlibuv/src/unix/kqueue.c
index ad09f40..bf183d5 100644
--- a/Utilities/cmlibuv/src/unix/kqueue.c
+++ b/Utilities/cmlibuv/src/unix/kqueue.c
@@ -82,7 +82,7 @@ int uv__io_fork(uv_loop_t* loop) {
process. So we sidestep the issue by pretending like we never
started it in the first place.
*/
- uv__has_forked_with_cfrunloop = 1;
+ uv__store_relaxed(&uv__has_forked_with_cfrunloop, 1);
uv__free(loop->cf_state);
loop->cf_state = NULL;
}
@@ -129,6 +129,8 @@ void uv__io_poll(uv_loop_t* loop, int timeout) {
int fd;
int op;
int i;
+ int user_timeout;
+ int reset_timeout;
if (loop->nfds == 0) {
assert(QUEUE_EMPTY(&loop->watcher_queue));
@@ -202,7 +204,21 @@ void uv__io_poll(uv_loop_t* loop, int timeout) {
base = loop->time;
count = 48; /* Benchmarks suggest this gives the best throughput. */
+ if (uv__get_internal_fields(loop)->flags & UV_METRICS_IDLE_TIME) {
+ reset_timeout = 1;
+ user_timeout = timeout;
+ timeout = 0;
+ } else {
+ reset_timeout = 0;
+ }
+
for (;; nevents = 0) {
+ /* Only need to set the provider_entry_time if timeout != 0. The function
+ * will return early if the loop isn't configured with UV_METRICS_IDLE_TIME.
+ */
+ if (timeout != 0)
+ uv__metrics_set_provider_entry_time(loop);
+
if (timeout != -1) {
spec.tv_sec = timeout / 1000;
spec.tv_nsec = (timeout % 1000) * 1000000;
@@ -228,6 +244,15 @@ void uv__io_poll(uv_loop_t* loop, int timeout) {
SAVE_ERRNO(uv__update_time(loop));
if (nfds == 0) {
+ if (reset_timeout != 0) {
+ timeout = user_timeout;
+ reset_timeout = 0;
+ if (timeout == -1)
+ continue;
+ if (timeout > 0)
+ goto update_timeout;
+ }
+
assert(timeout != -1);
return;
}
@@ -236,6 +261,11 @@ void uv__io_poll(uv_loop_t* loop, int timeout) {
if (errno != EINTR)
abort();
+ if (reset_timeout != 0) {
+ timeout = user_timeout;
+ reset_timeout = 0;
+ }
+
if (timeout == 0)
return;
@@ -276,6 +306,7 @@ void uv__io_poll(uv_loop_t* loop, int timeout) {
if (ev->filter == EVFILT_VNODE) {
assert(w->events == POLLIN);
assert(w->pevents == POLLIN);
+ uv__metrics_update_idle_time(loop);
w->cb(loop, w, ev->fflags); /* XXX always uv__fs_event() */
nevents++;
continue;
@@ -337,16 +368,25 @@ void uv__io_poll(uv_loop_t* loop, int timeout) {
/* Run signal watchers last. This also affects child process watchers
* because those are implemented in terms of signal watchers.
*/
- if (w == &loop->signal_io_watcher)
+ if (w == &loop->signal_io_watcher) {
have_signals = 1;
- else
+ } else {
+ uv__metrics_update_idle_time(loop);
w->cb(loop, w, revents);
+ }
nevents++;
}
- if (have_signals != 0)
+ if (reset_timeout != 0) {
+ timeout = user_timeout;
+ reset_timeout = 0;
+ }
+
+ if (have_signals != 0) {
+ uv__metrics_update_idle_time(loop);
loop->signal_io_watcher.cb(loop, &loop->signal_io_watcher, POLLIN);
+ }
loop->watchers[loop->nwatchers] = NULL;
loop->watchers[loop->nwatchers + 1] = NULL;
@@ -487,7 +527,7 @@ int uv_fs_event_start(uv_fs_event_t* handle,
if (!(statbuf.st_mode & S_IFDIR))
goto fallback;
- if (!uv__has_forked_with_cfrunloop) {
+ if (0 == uv__load_relaxed(&uv__has_forked_with_cfrunloop)) {
int r;
/* The fallback fd is no longer needed */
uv__close_nocheckstdio(fd);
@@ -522,8 +562,9 @@ int uv_fs_event_stop(uv_fs_event_t* handle) {
uv__handle_stop(handle);
#if defined(__APPLE__) && MAC_OS_X_VERSION_MAX_ALLOWED >= 1070
- if (!uv__has_forked_with_cfrunloop && handle->cf_cb != NULL)
- r = uv__fsevents_close(handle);
+ if (0 == uv__load_relaxed(&uv__has_forked_with_cfrunloop))
+ if (handle->cf_cb != NULL)
+ r = uv__fsevents_close(handle);
#endif
if (handle->event_watcher.fd != -1) {