unix,win: share loop watchers implementation
PR-URL: https://github.com/libuv/libuv/pull/974 Reviewed-By: Ben Noordhuis <info@bnoordhuis.nl>
This commit is contained in:
parent
de0054b6df
commit
3118e5a4e4
@ -27,6 +27,7 @@ libuv_la_LDFLAGS = -no-undefined -version-info 1:0:0
|
||||
libuv_la_SOURCES = src/fs-poll.c \
|
||||
src/heap-inl.h \
|
||||
src/inet.c \
|
||||
src/loop-watcher.c \
|
||||
src/queue.h \
|
||||
src/threadpool.c \
|
||||
src/uv-common.c \
|
||||
@ -57,7 +58,6 @@ libuv_la_SOURCES += src/win/async.c \
|
||||
src/win/handle.c \
|
||||
src/win/handle-inl.h \
|
||||
src/win/internal.h \
|
||||
src/win/loop-watcher.c \
|
||||
src/win/pipe.c \
|
||||
src/win/poll.c \
|
||||
src/win/process-stdio.c \
|
||||
@ -90,7 +90,6 @@ libuv_la_SOURCES += src/unix/async.c \
|
||||
src/unix/getaddrinfo.c \
|
||||
src/unix/getnameinfo.c \
|
||||
src/unix/internal.h \
|
||||
src/unix/loop-watcher.c \
|
||||
src/unix/loop.c \
|
||||
src/unix/pipe.c \
|
||||
src/unix/poll.c \
|
||||
|
||||
@ -42,6 +42,7 @@ INCLUDES = include/tree.h \
|
||||
|
||||
OBJS = src/fs-poll.o \
|
||||
src/inet.o \
|
||||
src/loop-watcher.o \
|
||||
src/threadpool.o \
|
||||
src/uv-common.o \
|
||||
src/version.o \
|
||||
@ -54,7 +55,6 @@ OBJS = src/fs-poll.o \
|
||||
src/win/getaddrinfo.o \
|
||||
src/win/getnameinfo.o \
|
||||
src/win/handle.o \
|
||||
src/win/loop-watcher.o \
|
||||
src/win/pipe.o \
|
||||
src/win/poll.o \
|
||||
src/win/process-stdio.o \
|
||||
|
||||
@ -31,6 +31,7 @@ include/uv-unix.h
|
||||
include/uv.h
|
||||
src/fs-poll.c
|
||||
src/inet.c
|
||||
src/loop-watcher.c
|
||||
src/queue.h
|
||||
src/unix/async.c
|
||||
src/unix/core.c
|
||||
@ -38,7 +39,6 @@ src/unix/dl.c
|
||||
src/unix/fs.c
|
||||
src/unix/getaddrinfo.c
|
||||
src/unix/internal.h
|
||||
src/unix/loop-watcher.c
|
||||
src/unix/loop.c
|
||||
src/unix/pipe.c
|
||||
src/unix/poll.c
|
||||
|
||||
@ -20,7 +20,7 @@
|
||||
*/
|
||||
|
||||
#include "uv.h"
|
||||
#include "internal.h"
|
||||
#include "uv-common.h"
|
||||
|
||||
#define UV_LOOP_WATCHER_DEFINE(name, type) \
|
||||
int uv_##name##_init(uv_loop_t* loop, uv_##name##_t* handle) { \
|
||||
@ -236,12 +236,9 @@ void uv__platform_invalidate_fd(uv_loop_t* loop, int fd);
|
||||
|
||||
/* various */
|
||||
void uv__async_close(uv_async_t* handle);
|
||||
void uv__check_close(uv_check_t* handle);
|
||||
void uv__fs_event_close(uv_fs_event_t* handle);
|
||||
void uv__idle_close(uv_idle_t* handle);
|
||||
void uv__pipe_close(uv_pipe_t* handle);
|
||||
void uv__poll_close(uv_poll_t* handle);
|
||||
void uv__prepare_close(uv_prepare_t* handle);
|
||||
void uv__process_close(uv_process_t* handle);
|
||||
void uv__stream_close(uv_stream_t* handle);
|
||||
void uv__tcp_close(uv_tcp_t* handle);
|
||||
|
||||
@ -216,4 +216,9 @@ void* uv__malloc(size_t size);
|
||||
void uv__free(void* ptr);
|
||||
void* uv__realloc(void* ptr, size_t size);
|
||||
|
||||
/* Loop watcher prototypes */
|
||||
void uv__idle_close(uv_idle_t* handle);
|
||||
void uv__prepare_close(uv_prepare_t* handle);
|
||||
void uv__check_close(uv_check_t* handle);
|
||||
|
||||
#endif /* UV_COMMON_H_ */
|
||||
|
||||
@ -132,7 +132,10 @@ INLINE static void uv_process_endgames(uv_loop_t* loop) {
|
||||
case UV_PREPARE:
|
||||
case UV_CHECK:
|
||||
case UV_IDLE:
|
||||
uv__loop_watcher_endgame(loop, handle);
|
||||
assert(handle->flags & UV__HANDLE_CLOSING);
|
||||
assert(!(handle->flags & UV_HANDLE_CLOSED));
|
||||
handle->flags |= UV_HANDLE_CLOSED;
|
||||
uv__handle_close(handle);
|
||||
break;
|
||||
|
||||
case UV_ASYNC:
|
||||
|
||||
@ -103,19 +103,19 @@ void uv_close(uv_handle_t* handle, uv_close_cb cb) {
|
||||
return;
|
||||
|
||||
case UV_PREPARE:
|
||||
uv_prepare_stop((uv_prepare_t*)handle);
|
||||
uv__prepare_close((uv_prepare_t*) handle);
|
||||
uv__handle_closing(handle);
|
||||
uv_want_endgame(loop, handle);
|
||||
return;
|
||||
|
||||
case UV_CHECK:
|
||||
uv_check_stop((uv_check_t*)handle);
|
||||
uv__check_close((uv_check_t*) handle);
|
||||
uv__handle_closing(handle);
|
||||
uv_want_endgame(loop, handle);
|
||||
return;
|
||||
|
||||
case UV_IDLE:
|
||||
uv_idle_stop((uv_idle_t*)handle);
|
||||
uv__idle_close((uv_idle_t*) handle);
|
||||
uv__handle_closing(handle);
|
||||
uv_want_endgame(loop, handle);
|
||||
return;
|
||||
|
||||
@ -1,77 +0,0 @@
|
||||
/* Copyright Joyent, Inc. and other Node contributors. All rights reserved.
|
||||
*
|
||||
* Permission is hereby granted, free of charge, to any person obtaining a copy
|
||||
* of this software and associated documentation files (the "Software"), to
|
||||
* deal in the Software without restriction, including without limitation the
|
||||
* rights to use, copy, modify, merge, publish, distribute, sublicense, and/or
|
||||
* sell copies of the Software, and to permit persons to whom the Software is
|
||||
* furnished to do so, subject to the following conditions:
|
||||
*
|
||||
* The above copyright notice and this permission notice shall be included in
|
||||
* all copies or substantial portions of the Software.
|
||||
*
|
||||
* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
||||
* IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
||||
* FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
|
||||
* AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
||||
* LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING
|
||||
* FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS
|
||||
* IN THE SOFTWARE.
|
||||
*/
|
||||
|
||||
#include <assert.h>
|
||||
|
||||
#include "uv.h"
|
||||
#include "internal.h"
|
||||
#include "handle-inl.h"
|
||||
|
||||
|
||||
void uv__loop_watcher_endgame(uv_loop_t* loop, uv_handle_t* handle) {
|
||||
if (handle->flags & UV__HANDLE_CLOSING) {
|
||||
assert(!(handle->flags & UV_HANDLE_CLOSED));
|
||||
handle->flags |= UV_HANDLE_CLOSED;
|
||||
uv__handle_close(handle);
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
#define UV_LOOP_WATCHER_DEFINE(name, type) \
|
||||
int uv_##name##_init(uv_loop_t* loop, uv_##name##_t* handle) { \
|
||||
uv__handle_init(loop, (uv_handle_t*)handle, UV_##type); \
|
||||
handle->name##_cb = NULL; \
|
||||
return 0; \
|
||||
} \
|
||||
\
|
||||
int uv_##name##_start(uv_##name##_t* handle, uv_##name##_cb cb) { \
|
||||
if (uv__is_active(handle)) return 0; \
|
||||
if (cb == NULL) return UV_EINVAL; \
|
||||
QUEUE_INSERT_HEAD(&handle->loop->name##_handles, &handle->queue); \
|
||||
handle->name##_cb = cb; \
|
||||
uv__handle_start(handle); \
|
||||
return 0; \
|
||||
} \
|
||||
\
|
||||
int uv_##name##_stop(uv_##name##_t* handle) { \
|
||||
if (!uv__is_active(handle)) return 0; \
|
||||
QUEUE_REMOVE(&handle->queue); \
|
||||
uv__handle_stop(handle); \
|
||||
return 0; \
|
||||
} \
|
||||
\
|
||||
void uv__run_##name(uv_loop_t* loop) { \
|
||||
uv_##name##_t* h; \
|
||||
QUEUE queue; \
|
||||
QUEUE* q; \
|
||||
QUEUE_MOVE(&loop->name##_handles, &queue); \
|
||||
while (!QUEUE_EMPTY(&queue)) { \
|
||||
q = QUEUE_HEAD(&queue); \
|
||||
h = QUEUE_DATA(q, uv_##name##_t, queue); \
|
||||
QUEUE_REMOVE(q); \
|
||||
QUEUE_INSERT_TAIL(&loop->name##_handles, q); \
|
||||
h->name##_cb(h); \
|
||||
} \
|
||||
} \
|
||||
|
||||
UV_LOOP_WATCHER_DEFINE(prepare, PREPARE)
|
||||
UV_LOOP_WATCHER_DEFINE(check, CHECK)
|
||||
UV_LOOP_WATCHER_DEFINE(idle, IDLE)
|
||||
3
uv.gyp
3
uv.gyp
@ -58,6 +58,7 @@
|
||||
'src/fs-poll.c',
|
||||
'src/heap-inl.h',
|
||||
'src/inet.c',
|
||||
'src/loop-watcher.c',
|
||||
'src/queue.h',
|
||||
'src/threadpool.c',
|
||||
'src/uv-common.c',
|
||||
@ -84,7 +85,6 @@
|
||||
'src/win/handle.c',
|
||||
'src/win/handle-inl.h',
|
||||
'src/win/internal.h',
|
||||
'src/win/loop-watcher.c',
|
||||
'src/win/pipe.c',
|
||||
'src/win/thread.c',
|
||||
'src/win/poll.c',
|
||||
@ -142,7 +142,6 @@
|
||||
'src/unix/getnameinfo.c',
|
||||
'src/unix/internal.h',
|
||||
'src/unix/loop.c',
|
||||
'src/unix/loop-watcher.c',
|
||||
'src/unix/pipe.c',
|
||||
'src/unix/poll.c',
|
||||
'src/unix/process.c',
|
||||
|
||||
Loading…
Reference in New Issue
Block a user