unix: move inotify init logic to loop.c

This commit is contained in:
Ben Noordhuis 2012-04-05 15:13:14 +02:00
parent 68bed698fc
commit f4e7537184
3 changed files with 10 additions and 26 deletions

View File

@ -157,14 +157,4 @@ void uv__udp_close(uv_udp_t* handle);
int uv__make_socketpair(int fds[2], int flags);
int uv__make_pipe(int fds[2], int flags);
#if __linux__
void uv__inotify_loop_init(uv_loop_t* loop);
void uv__inotify_loop_delete(uv_loop_t* loop);
# define uv__loop_platform_init(loop) uv__inotify_loop_init(loop)
# define uv__loop_platform_delete(loop) uv__inotify_loop_delete(loop)
#else
# define uv__loop_platform_init(loop)
# define uv__loop_platform_delete(loop)
#endif
#endif /* UV_UNIX_INTERNAL_H_ */

View File

@ -51,20 +51,6 @@ static int compare_watchers(const uv_fs_event_t* a, const uv_fs_event_t* b) {
RB_GENERATE_STATIC(uv__inotify_watchers, uv_fs_event_s, node, compare_watchers)
void uv__inotify_loop_init(uv_loop_t* loop) {
RB_INIT(&loop->inotify_watchers);
loop->inotify_fd = -1;
}
void uv__inotify_loop_delete(uv_loop_t* loop) {
if (loop->inotify_fd == -1) return;
ev_io_stop(loop->ev, &loop->inotify_read_watcher);
close(loop->inotify_fd);
loop->inotify_fd = -1;
}
static void uv__inotify_read(EV_P_ ev_io* w, int revents);

View File

@ -37,7 +37,10 @@ int uv__loop_init(uv_loop_t* loop, int default_loop) {
loop->ev = (default_loop ? ev_default_loop : ev_loop_new)(flags);
ev_set_userdata(loop->ev, loop);
eio_channel_init(&loop->uv_eio_channel, loop);
uv__loop_platform_init(loop);
#if __linux__
RB_INIT(&loop->inotify_watchers);
loop->inotify_fd = -1;
#endif
return 0;
}
@ -45,5 +48,10 @@ int uv__loop_init(uv_loop_t* loop, int default_loop) {
void uv__loop_delete(uv_loop_t* loop) {
uv_ares_destroy(loop, loop->channel);
ev_loop_destroy(loop->ev);
uv__loop_platform_delete(loop);
#if __linux__
if (loop->inotify_fd == -1) return;
ev_io_stop(loop->ev, &loop->inotify_read_watcher);
close(loop->inotify_fd);
loop->inotify_fd = -1;
#endif
}