unix,windows: refactor request init logic
Fixes a TODO in src/threadpool.c. Updates the Windows code to drop the unused `loop` parameter in calls to uv_req_init(). PR-URL: https://github.com/libuv/libuv/pull/1091 Reviewed-By: Colin Ihrig <cjihrig@gmail.com> Reviewed-By: Santiago Gimeno <santiago.gimeno@gmail.com> Reviewed-By: Saúl Ibarra Corretgé <saghul@gmail.com>
This commit is contained in:
parent
463800ffc1
commit
87df1448a4
@ -23,18 +23,6 @@
|
||||
|
||||
#if !defined(_WIN32)
|
||||
# include "unix/internal.h"
|
||||
#else
|
||||
# include "win/req-inl.h"
|
||||
/* TODO(saghul): unify internal req functions */
|
||||
static void uv__req_init(uv_loop_t* loop,
|
||||
uv_req_t* req,
|
||||
uv_req_type type) {
|
||||
uv_req_init(loop, req);
|
||||
req->type = type;
|
||||
uv__req_register(loop, req);
|
||||
}
|
||||
# define uv__req_init(loop, req, type) \
|
||||
uv__req_init((loop), (uv_req_t*)(req), (type))
|
||||
#endif
|
||||
|
||||
#include <stdlib.h>
|
||||
|
||||
@ -303,15 +303,6 @@ static const int kFSEventStreamEventFlagItemIsSymlink = 0x00040000;
|
||||
|
||||
#endif /* defined(__APPLE__) */
|
||||
|
||||
UV_UNUSED(static void uv__req_init(uv_loop_t* loop,
|
||||
uv_req_t* req,
|
||||
uv_req_type type)) {
|
||||
req->type = type;
|
||||
uv__req_register(loop, req);
|
||||
}
|
||||
#define uv__req_init(loop, req, type) \
|
||||
uv__req_init((loop), (uv_req_t*)(req), (type))
|
||||
|
||||
UV_UNUSED(static void uv__update_time(uv_loop_t* loop)) {
|
||||
/* Use a fast time source if available. We only need millisecond precision.
|
||||
*/
|
||||
|
||||
@ -218,6 +218,30 @@ void uv__fs_scandir_cleanup(uv_fs_t* req);
|
||||
} \
|
||||
while (0)
|
||||
|
||||
/* Note: uses an open-coded version of SET_REQ_SUCCESS() because of
|
||||
* a circular dependency between src/uv-common.h and src/win/internal.h.
|
||||
*/
|
||||
#if defined(_WIN32)
|
||||
# define UV_REQ_INIT(req, typ) \
|
||||
do { \
|
||||
(req)->type = (typ); \
|
||||
(req)->u.io.overlapped.Internal = 0; /* SET_REQ_SUCCESS() */ \
|
||||
} \
|
||||
while (0)
|
||||
#else
|
||||
# define UV_REQ_INIT(req, typ) \
|
||||
do { \
|
||||
(req)->type = (typ); \
|
||||
} \
|
||||
while (0)
|
||||
#endif
|
||||
|
||||
#define uv__req_init(loop, req, typ) \
|
||||
do { \
|
||||
UV_REQ_INIT(req, typ); \
|
||||
uv__req_register(loop, req); \
|
||||
} \
|
||||
while (0)
|
||||
|
||||
/* Allocator prototypes */
|
||||
void *uv__calloc(size_t count, size_t size);
|
||||
|
||||
@ -45,8 +45,7 @@ int uv_async_init(uv_loop_t* loop, uv_async_t* handle, uv_async_cb async_cb) {
|
||||
handle->async_cb = async_cb;
|
||||
|
||||
req = &handle->async_req;
|
||||
uv_req_init(loop, req);
|
||||
req->type = UV_WAKEUP;
|
||||
UV_REQ_INIT(req, UV_WAKEUP);
|
||||
req->data = handle;
|
||||
|
||||
uv__handle_start(handle);
|
||||
|
||||
@ -131,8 +131,7 @@ int uv_fs_event_init(uv_loop_t* loop, uv_fs_event_t* handle) {
|
||||
handle->short_filew = NULL;
|
||||
handle->dirw = NULL;
|
||||
|
||||
uv_req_init(loop, (uv_req_t*)&handle->req);
|
||||
handle->req.type = UV_FS_EVENT_REQ;
|
||||
UV_REQ_INIT(&handle->req, UV_FS_EVENT_REQ);
|
||||
handle->req.data = handle;
|
||||
|
||||
return 0;
|
||||
|
||||
@ -220,9 +220,7 @@ INLINE static int fs__capture_path(uv_fs_t* req, const char* path,
|
||||
|
||||
INLINE static void uv_fs_req_init(uv_loop_t* loop, uv_fs_t* req,
|
||||
uv_fs_type fs_type, const uv_fs_cb cb) {
|
||||
uv_req_init(loop, (uv_req_t*) req);
|
||||
|
||||
req->type = UV_FS;
|
||||
UV_REQ_INIT(req, UV_FS);
|
||||
req->loop = loop;
|
||||
req->flags = 0;
|
||||
req->fs_type = fs_type;
|
||||
|
||||
@ -265,11 +265,9 @@ int uv_getaddrinfo(uv_loop_t* loop,
|
||||
return UV_EINVAL;
|
||||
}
|
||||
|
||||
uv_req_init(loop, (uv_req_t*)req);
|
||||
|
||||
UV_REQ_INIT(req, UV_GETADDRINFO);
|
||||
req->getaddrinfo_cb = getaddrinfo_cb;
|
||||
req->addrinfo = NULL;
|
||||
req->type = UV_GETADDRINFO;
|
||||
req->loop = loop;
|
||||
req->retcode = 0;
|
||||
|
||||
|
||||
@ -127,12 +127,11 @@ int uv_getnameinfo(uv_loop_t* loop,
|
||||
return UV_EINVAL;
|
||||
}
|
||||
|
||||
uv_req_init(loop, (uv_req_t*)req);
|
||||
UV_REQ_INIT(req, UV_GETNAMEINFO);
|
||||
uv__req_register(loop, req);
|
||||
|
||||
req->getnameinfo_cb = getnameinfo_cb;
|
||||
req->flags = flags;
|
||||
req->type = UV_GETNAMEINFO;
|
||||
req->loop = loop;
|
||||
req->retcode = 0;
|
||||
|
||||
|
||||
@ -103,7 +103,7 @@ int uv_pipe_init(uv_loop_t* loop, uv_pipe_t* handle, int ipc) {
|
||||
handle->pipe.conn.non_overlapped_writes_tail = NULL;
|
||||
handle->pipe.conn.readfile_thread = NULL;
|
||||
|
||||
uv_req_init(loop, (uv_req_t*) &handle->pipe.conn.ipc_header_write_req);
|
||||
UV_REQ_INIT(&handle->pipe.conn.ipc_header_write_req, UV_UNKNOWN_REQ);
|
||||
|
||||
return 0;
|
||||
}
|
||||
@ -505,8 +505,7 @@ int uv_pipe_bind(uv_pipe_t* handle, const char* name) {
|
||||
|
||||
for (i = 0; i < handle->pipe.serv.pending_instances; i++) {
|
||||
req = &handle->pipe.serv.accept_reqs[i];
|
||||
uv_req_init(loop, (uv_req_t*) req);
|
||||
req->type = UV_ACCEPT;
|
||||
UV_REQ_INIT(req, UV_ACCEPT);
|
||||
req->data = handle;
|
||||
req->pipeHandle = INVALID_HANDLE_VALUE;
|
||||
req->next_pending = NULL;
|
||||
@ -626,8 +625,7 @@ void uv_pipe_connect(uv_connect_t* req, uv_pipe_t* handle,
|
||||
HANDLE pipeHandle = INVALID_HANDLE_VALUE;
|
||||
DWORD duplex_flags;
|
||||
|
||||
uv_req_init(loop, (uv_req_t*) req);
|
||||
req->type = UV_CONNECT;
|
||||
UV_REQ_INIT(req, UV_CONNECT);
|
||||
req->handle = (uv_stream_t*) handle;
|
||||
req->cb = cb;
|
||||
|
||||
@ -1239,8 +1237,7 @@ static int uv_pipe_write_impl(uv_loop_t* loop,
|
||||
|
||||
assert(handle->handle != INVALID_HANDLE_VALUE);
|
||||
|
||||
uv_req_init(loop, (uv_req_t*) req);
|
||||
req->type = UV_WRITE;
|
||||
UV_REQ_INIT(req, UV_WRITE);
|
||||
req->handle = (uv_stream_t*) handle;
|
||||
req->cb = cb;
|
||||
req->ipc_header = 0;
|
||||
@ -1301,8 +1298,7 @@ static int uv_pipe_write_impl(uv_loop_t* loop,
|
||||
}
|
||||
}
|
||||
|
||||
uv_req_init(loop, (uv_req_t*) ipc_header_req);
|
||||
ipc_header_req->type = UV_WRITE;
|
||||
UV_REQ_INIT(ipc_header_req, UV_WRITE);
|
||||
ipc_header_req->handle = (uv_stream_t*) handle;
|
||||
ipc_header_req->cb = NULL;
|
||||
ipc_header_req->ipc_header = 1;
|
||||
|
||||
@ -572,13 +572,11 @@ int uv_poll_init_socket(uv_loop_t* loop, uv_poll_t* handle,
|
||||
|
||||
/* Initialize 2 poll reqs. */
|
||||
handle->submitted_events_1 = 0;
|
||||
uv_req_init(loop, (uv_req_t*) &(handle->poll_req_1));
|
||||
handle->poll_req_1.type = UV_POLL_REQ;
|
||||
UV_REQ_INIT(&handle->poll_req_1, UV_POLL_REQ);
|
||||
handle->poll_req_1.data = handle;
|
||||
|
||||
handle->submitted_events_2 = 0;
|
||||
uv_req_init(loop, (uv_req_t*) &(handle->poll_req_2));
|
||||
handle->poll_req_2.type = UV_POLL_REQ;
|
||||
UV_REQ_INIT(&handle->poll_req_2, UV_POLL_REQ);
|
||||
handle->poll_req_2.data = handle;
|
||||
|
||||
return 0;
|
||||
|
||||
@ -148,8 +148,7 @@ static void uv_process_init(uv_loop_t* loop, uv_process_t* handle) {
|
||||
handle->child_stdio_buffer = NULL;
|
||||
handle->exit_cb_pending = 0;
|
||||
|
||||
uv_req_init(loop, (uv_req_t*)&handle->exit_req);
|
||||
handle->exit_req.type = UV_PROCESS_EXIT;
|
||||
UV_REQ_INIT(&handle->exit_req, UV_PROCESS_EXIT);
|
||||
handle->exit_req.data = handle;
|
||||
}
|
||||
|
||||
|
||||
@ -34,6 +34,9 @@
|
||||
#define SET_REQ_ERROR(req, error) \
|
||||
SET_REQ_STATUS((req), NTSTATUS_FROM_WIN32((error)))
|
||||
|
||||
/* Note: used open-coded in UV_REQ_INIT() because of a circular dependency
|
||||
* between src/uv-common.h and src/win/internal.h.
|
||||
*/
|
||||
#define SET_REQ_SUCCESS(req) \
|
||||
SET_REQ_STATUS((req), STATUS_SUCCESS)
|
||||
|
||||
@ -79,12 +82,6 @@
|
||||
}
|
||||
|
||||
|
||||
INLINE static void uv_req_init(uv_loop_t* loop, uv_req_t* req) {
|
||||
req->type = UV_UNKNOWN_REQ;
|
||||
SET_REQ_SUCCESS(req);
|
||||
}
|
||||
|
||||
|
||||
INLINE static uv_req_t* uv_overlapped_to_req(OVERLAPPED* overlapped) {
|
||||
return CONTAINING_RECORD(overlapped, uv_req_t, u.io.overlapped);
|
||||
}
|
||||
|
||||
@ -140,17 +140,13 @@ static BOOL WINAPI uv__signal_control_handler(DWORD type) {
|
||||
|
||||
|
||||
int uv_signal_init(uv_loop_t* loop, uv_signal_t* handle) {
|
||||
uv_req_t* req;
|
||||
|
||||
uv__handle_init(loop, (uv_handle_t*) handle, UV_SIGNAL);
|
||||
handle->pending_signum = 0;
|
||||
handle->signum = 0;
|
||||
handle->signal_cb = NULL;
|
||||
|
||||
req = &handle->signal_req;
|
||||
uv_req_init(loop, req);
|
||||
req->type = UV_SIGNAL_REQ;
|
||||
req->data = handle;
|
||||
UV_REQ_INIT(&handle->signal_req, UV_SIGNAL_REQ);
|
||||
handle->signal_req.data = handle;
|
||||
|
||||
return 0;
|
||||
}
|
||||
|
||||
@ -43,10 +43,9 @@ INLINE static void uv_connection_init(uv_stream_t* handle) {
|
||||
handle->flags |= UV_HANDLE_CONNECTION;
|
||||
handle->stream.conn.write_reqs_pending = 0;
|
||||
|
||||
uv_req_init(handle->loop, (uv_req_t*) &(handle->read_req));
|
||||
UV_REQ_INIT(&handle->read_req, UV_READ);
|
||||
handle->read_req.event_handle = NULL;
|
||||
handle->read_req.wait_handle = INVALID_HANDLE_VALUE;
|
||||
handle->read_req.type = UV_READ;
|
||||
handle->read_req.data = handle;
|
||||
|
||||
handle->stream.conn.shutdown_req = NULL;
|
||||
|
||||
@ -210,8 +210,7 @@ int uv_shutdown(uv_shutdown_t* req, uv_stream_t* handle, uv_shutdown_cb cb) {
|
||||
return UV_EPIPE;
|
||||
}
|
||||
|
||||
uv_req_init(loop, (uv_req_t*) req);
|
||||
req->type = UV_SHUTDOWN;
|
||||
UV_REQ_INIT(req, UV_SHUTDOWN);
|
||||
req->handle = handle;
|
||||
req->cb = cb;
|
||||
|
||||
|
||||
@ -555,7 +555,6 @@ static void uv_tcp_queue_read(uv_loop_t* loop, uv_tcp_t* handle) {
|
||||
|
||||
|
||||
int uv_tcp_listen(uv_tcp_t* handle, int backlog, uv_connection_cb cb) {
|
||||
uv_loop_t* loop = handle->loop;
|
||||
unsigned int i, simultaneous_accepts;
|
||||
uv_tcp_accept_t* req;
|
||||
int err;
|
||||
@ -612,8 +611,7 @@ int uv_tcp_listen(uv_tcp_t* handle, int backlog, uv_connection_cb cb) {
|
||||
|
||||
for (i = 0; i < simultaneous_accepts; i++) {
|
||||
req = &handle->tcp.serv.accept_reqs[i];
|
||||
uv_req_init(loop, (uv_req_t*)req);
|
||||
req->type = UV_ACCEPT;
|
||||
UV_REQ_INIT(req, UV_ACCEPT);
|
||||
req->accept_socket = INVALID_SOCKET;
|
||||
req->data = handle;
|
||||
|
||||
@ -635,8 +633,7 @@ int uv_tcp_listen(uv_tcp_t* handle, int backlog, uv_connection_cb cb) {
|
||||
/* try to clean up {uv_simultaneous_server_accepts} requests. */
|
||||
for (i = simultaneous_accepts; i < uv_simultaneous_server_accepts; i++) {
|
||||
req = &handle->tcp.serv.accept_reqs[i];
|
||||
uv_req_init(loop, (uv_req_t*) req);
|
||||
req->type = UV_ACCEPT;
|
||||
UV_REQ_INIT(req, UV_ACCEPT);
|
||||
req->accept_socket = INVALID_SOCKET;
|
||||
req->data = handle;
|
||||
req->wait_handle = INVALID_HANDLE_VALUE;
|
||||
@ -779,8 +776,7 @@ static int uv_tcp_try_connect(uv_connect_t* req,
|
||||
}
|
||||
}
|
||||
|
||||
uv_req_init(loop, (uv_req_t*) req);
|
||||
req->type = UV_CONNECT;
|
||||
UV_REQ_INIT(req, UV_CONNECT);
|
||||
req->handle = (uv_stream_t*) handle;
|
||||
req->cb = cb;
|
||||
memset(&req->u.io.overlapped, 0, sizeof(req->u.io.overlapped));
|
||||
@ -863,8 +859,7 @@ int uv_tcp_write(uv_loop_t* loop,
|
||||
int result;
|
||||
DWORD bytes;
|
||||
|
||||
uv_req_init(loop, (uv_req_t*) req);
|
||||
req->type = UV_WRITE;
|
||||
UV_REQ_INIT(req, UV_WRITE);
|
||||
req->handle = (uv_stream_t*) handle;
|
||||
req->cb = cb;
|
||||
|
||||
|
||||
@ -2126,8 +2126,7 @@ int uv_tty_write(uv_loop_t* loop,
|
||||
uv_write_cb cb) {
|
||||
DWORD error;
|
||||
|
||||
uv_req_init(loop, (uv_req_t*) req);
|
||||
req->type = UV_WRITE;
|
||||
UV_REQ_INIT(req, UV_WRITE);
|
||||
req->handle = (uv_stream_t*) handle;
|
||||
req->cb = cb;
|
||||
|
||||
|
||||
@ -142,8 +142,7 @@ int uv_udp_init_ex(uv_loop_t* loop, uv_udp_t* handle, unsigned int flags) {
|
||||
handle->func_wsarecvfrom = WSARecvFrom;
|
||||
handle->send_queue_size = 0;
|
||||
handle->send_queue_count = 0;
|
||||
uv_req_init(loop, (uv_req_t*) &(handle->recv_req));
|
||||
handle->recv_req.type = UV_UDP_RECV;
|
||||
UV_REQ_INIT(&handle->recv_req, UV_UDP_RECV);
|
||||
handle->recv_req.data = handle;
|
||||
|
||||
/* If anything fails beyond this point we need to remove the handle from
|
||||
@ -417,8 +416,7 @@ static int uv__send(uv_udp_send_t* req,
|
||||
uv_loop_t* loop = handle->loop;
|
||||
DWORD result, bytes;
|
||||
|
||||
uv_req_init(loop, (uv_req_t*) req);
|
||||
req->type = UV_UDP_SEND;
|
||||
UV_REQ_INIT(req, UV_UDP_SEND);
|
||||
req->handle = handle;
|
||||
req->cb = cb;
|
||||
memset(&req->u.io.overlapped, 0, sizeof(req->u.io.overlapped));
|
||||
|
||||
Loading…
Reference in New Issue
Block a user