Lines Matching refs:loop

36 int uv__platform_loop_init(uv_loop_t* loop) {  in uv__platform_loop_init()  argument
37 loop->poll_fds = NULL; in uv__platform_loop_init()
38 loop->poll_fds_used = 0; in uv__platform_loop_init()
39 loop->poll_fds_size = 0; in uv__platform_loop_init()
40 loop->poll_fds_iterating = 0; in uv__platform_loop_init()
44 void uv__platform_loop_delete(uv_loop_t* loop) { in uv__platform_loop_delete() argument
45 uv__free(loop->poll_fds); in uv__platform_loop_delete()
46 loop->poll_fds = NULL; in uv__platform_loop_delete()
49 int uv__io_fork(uv_loop_t* loop) { in uv__io_fork() argument
50 uv__platform_loop_delete(loop); in uv__io_fork()
51 return uv__platform_loop_init(loop); in uv__io_fork()
55 static void uv__pollfds_maybe_resize(uv_loop_t* loop) { in uv__pollfds_maybe_resize() argument
60 if (loop->poll_fds_used < loop->poll_fds_size) in uv__pollfds_maybe_resize()
63 n = loop->poll_fds_size ? loop->poll_fds_size * 2 : 64; in uv__pollfds_maybe_resize()
64 p = uv__reallocf(loop->poll_fds, n * sizeof(*loop->poll_fds)); in uv__pollfds_maybe_resize()
68 loop->poll_fds = p; in uv__pollfds_maybe_resize()
69 for (i = loop->poll_fds_size; i < n; i++) { in uv__pollfds_maybe_resize()
70 loop->poll_fds[i].fd = -1; in uv__pollfds_maybe_resize()
71 loop->poll_fds[i].events = 0; in uv__pollfds_maybe_resize()
72 loop->poll_fds[i].revents = 0; in uv__pollfds_maybe_resize()
74 loop->poll_fds_size = n; in uv__pollfds_maybe_resize()
78 static void uv__pollfds_swap(uv_loop_t* loop, size_t l, size_t r) { in uv__pollfds_swap() argument
80 pfd = loop->poll_fds[l]; in uv__pollfds_swap()
81 loop->poll_fds[l] = loop->poll_fds[r]; in uv__pollfds_swap()
82 loop->poll_fds[r] = pfd; in uv__pollfds_swap()
86 static void uv__pollfds_add(uv_loop_t* loop, uv__io_t* w) { in uv__pollfds_add() argument
91 assert(!loop->poll_fds_iterating); in uv__pollfds_add()
92 for (i = 0; i < loop->poll_fds_used; ++i) { in uv__pollfds_add()
93 if (loop->poll_fds[i].fd == w->fd) { in uv__pollfds_add()
94 loop->poll_fds[i].events = w->pevents; in uv__pollfds_add()
100 uv__pollfds_maybe_resize(loop); in uv__pollfds_add()
101 pe = &loop->poll_fds[loop->poll_fds_used++]; in uv__pollfds_add()
107 static void uv__pollfds_del(uv_loop_t* loop, int fd) { in uv__pollfds_del() argument
109 assert(!loop->poll_fds_iterating); in uv__pollfds_del()
110 for (i = 0; i < loop->poll_fds_used;) { in uv__pollfds_del()
111 if (loop->poll_fds[i].fd == fd) { in uv__pollfds_del()
113 --loop->poll_fds_used; in uv__pollfds_del()
114 uv__pollfds_swap(loop, i, loop->poll_fds_used); in uv__pollfds_del()
115 loop->poll_fds[loop->poll_fds_used].fd = -1; in uv__pollfds_del()
116 loop->poll_fds[loop->poll_fds_used].events = 0; in uv__pollfds_del()
117 loop->poll_fds[loop->poll_fds_used].revents = 0; in uv__pollfds_del()
134 void uv__io_poll(uv_loop_t* loop, int timeout) { in uv__io_poll() argument
151 if (loop->nfds == 0) { in uv__io_poll()
152 assert(uv__queue_empty(&loop->watcher_queue)); in uv__io_poll()
156 lfields = uv__get_internal_fields(loop); in uv__io_poll()
159 while (!uv__queue_empty(&loop->watcher_queue)) { in uv__io_poll()
160 q = uv__queue_head(&loop->watcher_queue); in uv__io_poll()
167 assert(w->fd < (int) loop->nwatchers); in uv__io_poll()
169 uv__pollfds_add(loop, w); in uv__io_poll()
176 if (loop->flags & UV_LOOP_BLOCK_SIGPROF) { in uv__io_poll()
183 time_base = loop->time; in uv__io_poll()
202 uv__metrics_set_provider_entry_time(loop); in uv__io_poll()
213 nfds = poll(loop->poll_fds, (nfds_t)loop->poll_fds_used, timeout); in uv__io_poll()
222 SAVE_ERRNO(uv__update_time(loop)); in uv__io_poll()
260 loop->poll_fds_iterating = 1; in uv__io_poll()
267 for (i = 0; i < loop->poll_fds_used; i++) { in uv__io_poll()
268 pe = loop->poll_fds + i; in uv__io_poll()
276 assert((unsigned) fd < loop->nwatchers); in uv__io_poll()
278 w = loop->watchers[fd]; in uv__io_poll()
282 uv__platform_invalidate_fd(loop, fd); in uv__io_poll()
293 if (w == &loop->signal_io_watcher) { in uv__io_poll()
296 uv__metrics_update_idle_time(loop); in uv__io_poll()
297 w->cb(loop, w, pe->revents); in uv__io_poll()
304 uv__metrics_inc_events(loop, nevents); in uv__io_poll()
308 uv__metrics_inc_events_waiting(loop, nevents); in uv__io_poll()
312 uv__metrics_update_idle_time(loop); in uv__io_poll()
313 loop->signal_io_watcher.cb(loop, &loop->signal_io_watcher, POLLIN); in uv__io_poll()
316 loop->poll_fds_iterating = 0; in uv__io_poll()
319 uv__pollfds_del(loop, -1); in uv__io_poll()
336 time_diff = loop->time - time_base; in uv__io_poll()
347 void uv__platform_invalidate_fd(uv_loop_t* loop, int fd) { in uv__platform_invalidate_fd() argument
352 if (loop->poll_fds_iterating) { in uv__platform_invalidate_fd()
354 for (i = 0; i < loop->poll_fds_used; i++) in uv__platform_invalidate_fd()
355 if (loop->poll_fds[i].fd == fd) { in uv__platform_invalidate_fd()
356 loop->poll_fds[i].fd = -1; in uv__platform_invalidate_fd()
357 loop->poll_fds[i].events = 0; in uv__platform_invalidate_fd()
358 loop->poll_fds[i].revents = 0; in uv__platform_invalidate_fd()
362 uv__pollfds_del(loop, fd); in uv__platform_invalidate_fd()
367 int uv__io_check_fd(uv_loop_t* loop, int fd) { in uv__io_check_fd() argument