Skip to content
This repository has been archived by the owner on May 4, 2018. It is now read-only.

Commit

Permalink
Browse files Browse the repository at this point in the history
unix, windows: share uv__handle_init()
  • Loading branch information
bnoordhuis committed Jun 12, 2012
1 parent b7e150e commit 95e89c6
Show file tree
Hide file tree
Showing 14 changed files with 27 additions and 43 deletions.
12 changes: 0 additions & 12 deletions src/unix/core.c
Expand Up @@ -271,18 +271,6 @@ int uv_run_once(uv_loop_t* loop) {
}


void uv__handle_init(uv_loop_t* loop, uv_handle_t* handle,
uv_handle_type type) {
loop->counters.handle_init++;

handle->loop = loop;
handle->type = type;
handle->flags = UV__HANDLE_REF; /* ref the loop when active */
handle->next_closing = NULL;
ngx_queue_insert_tail(&loop->handle_queue, &handle->handle_queue);
}


void uv_update_time(uv_loop_t* loop) {
loop->time = uv_hrtime() / 1000000;
}
Expand Down
13 changes: 13 additions & 0 deletions src/uv-common.h
Expand Up @@ -153,4 +153,17 @@ UNUSED static void uv__handle_unref(uv_handle_t* h) {
}
#define uv__handle_unref(h) uv__handle_unref((uv_handle_t*)(h))

UNUSED static void uv__handle_init(uv_loop_t* loop,
uv_handle_t* handle,
uv_handle_type type) {
loop->counters.handle_init++;
handle->loop = loop;
handle->type = type;
handle->flags = UV__HANDLE_REF; /* ref the loop when active */
ngx_queue_insert_tail(&loop->handle_queue, &handle->handle_queue);
#ifndef _WIN32
handle->next_closing = NULL;
#endif
}

#endif /* UV_COMMON_H_ */
3 changes: 1 addition & 2 deletions src/win/async.c
Expand Up @@ -69,8 +69,7 @@ void uv_async_endgame(uv_loop_t* loop, uv_async_t* handle) {
int uv_async_init(uv_loop_t* loop, uv_async_t* handle, uv_async_cb async_cb) {
uv_req_t* req;

uv_handle_init(loop, (uv_handle_t*) handle);
handle->type = UV_ASYNC;
uv__handle_init(loop, (uv_handle_t*) handle, UV_ASYNC);
handle->async_sent = 0;
handle->async_cb = async_cb;

Expand Down
3 changes: 1 addition & 2 deletions src/win/fs-event.c
Expand Up @@ -36,8 +36,7 @@ const unsigned int uv_directory_watcher_buffer_size = 4096;

static void uv_fs_event_init_handle(uv_loop_t* loop, uv_fs_event_t* handle,
const char* filename, uv_fs_event_cb cb) {
uv_handle_init(loop, (uv_handle_t*) handle);
handle->type = UV_FS_EVENT;
uv__handle_init(loop, (uv_handle_t*) handle, UV_FS_EVENT);
handle->cb = cb;
handle->dir_handle = INVALID_HANDLE_VALUE;
handle->buffer = NULL;
Expand Down
9 changes: 0 additions & 9 deletions src/win/handle-inl.h
Expand Up @@ -69,15 +69,6 @@
} while (0)


INLINE static void uv_handle_init(uv_loop_t* loop, uv_handle_t* handle) {
handle->loop = loop;
handle->flags = UV__HANDLE_REF;
ngx_queue_insert_tail(&loop->handle_queue, &handle->handle_queue);

loop->counters.handle_init++;
}


INLINE static void uv_want_endgame(uv_loop_t* loop, uv_handle_t* handle) {
if (!(handle->flags & UV_HANDLE_ENDGAME_QUEUED)) {
handle->flags |= UV_HANDLE_ENDGAME_QUEUED;
Expand Down
3 changes: 1 addition & 2 deletions src/win/loop-watcher.c
Expand Up @@ -38,8 +38,7 @@ void uv_loop_watcher_endgame(uv_loop_t* loop, uv_handle_t* handle) {

#define UV_LOOP_WATCHER_DEFINE(name, NAME) \
int uv_##name##_init(uv_loop_t* loop, uv_##name##_t* handle) { \
uv_handle_init(loop, (uv_handle_t*) handle); \
handle->type = UV_##NAME; \
uv__handle_init(loop, (uv_handle_t*) handle, UV_##NAME); \
loop->counters.name##_init++; \
\
return 0; \
Expand Down
3 changes: 1 addition & 2 deletions src/win/pipe.c
Expand Up @@ -74,9 +74,8 @@ static void uv_unique_pipe_name(char* ptr, char* name, size_t size) {


int uv_pipe_init(uv_loop_t* loop, uv_pipe_t* handle, int ipc) {
uv_stream_init(loop, (uv_stream_t*)handle);
uv_stream_init(loop, (uv_stream_t*)handle, UV_NAMED_PIPE);

handle->type = UV_NAMED_PIPE;
handle->reqs_pending = 0;
handle->handle = INVALID_HANDLE_VALUE;
handle->name = NULL;
Expand Down
3 changes: 1 addition & 2 deletions src/win/poll.c
Expand Up @@ -519,8 +519,7 @@ int uv_poll_init_socket(uv_loop_t* loop, uv_poll_t* handle,
socket = base_socket;
}

uv_handle_init(loop, (uv_handle_t*) handle);
handle->type = UV_POLL;
uv__handle_init(loop, (uv_handle_t*) handle, UV_POLL);
handle->socket = socket;
handle->events = 0;

Expand Down
3 changes: 1 addition & 2 deletions src/win/process.c
Expand Up @@ -101,8 +101,7 @@ typedef struct env_var {


static void uv_process_init(uv_loop_t* loop, uv_process_t* handle) {
uv_handle_init(loop, (uv_handle_t*) handle);
handle->type = UV_PROCESS;
uv__handle_init(loop, (uv_handle_t*) handle, UV_PROCESS);
handle->exit_cb = NULL;
handle->pid = 0;
handle->exit_signal = 0;
Expand Down
6 changes: 4 additions & 2 deletions src/win/stream-inl.h
Expand Up @@ -30,8 +30,10 @@
#include "req-inl.h"


INLINE static void uv_stream_init(uv_loop_t* loop, uv_stream_t* handle) {
uv_handle_init(loop, (uv_handle_t*) handle);
INLINE static void uv_stream_init(uv_loop_t* loop,
uv_stream_t* handle,
uv_handle_type type) {
uv__handle_init(loop, (uv_handle_t*) handle, type);
handle->write_queue_size = 0;
handle->activecnt = 0;

Expand Down
3 changes: 1 addition & 2 deletions src/win/tcp.c
Expand Up @@ -146,9 +146,8 @@ static int uv_tcp_set_socket(uv_loop_t* loop, uv_tcp_t* handle,


int uv_tcp_init(uv_loop_t* loop, uv_tcp_t* handle) {
uv_stream_init(loop, (uv_stream_t*) handle);
uv_stream_init(loop, (uv_stream_t*) handle, UV_TCP);

handle->type = UV_TCP;
handle->accept_reqs = NULL;
handle->pending_accepts = NULL;
handle->socket = INVALID_SOCKET;
Expand Down
3 changes: 1 addition & 2 deletions src/win/timer.c
Expand Up @@ -67,8 +67,7 @@ RB_GENERATE_STATIC(uv_timer_tree_s, uv_timer_s, tree_entry, uv_timer_compare);


int uv_timer_init(uv_loop_t* loop, uv_timer_t* handle) {
uv_handle_init(loop, (uv_handle_t*) handle);
handle->type = UV_TIMER;
uv__handle_init(loop, (uv_handle_t*) handle, UV_TIMER);
handle->timer_cb = NULL;
handle->repeat = 0;

Expand Down
3 changes: 1 addition & 2 deletions src/win/tty.c
Expand Up @@ -112,10 +112,9 @@ int uv_tty_init(uv_loop_t* loop, uv_tty_t* tty, uv_file fd, int readable) {
LeaveCriticalSection(&uv_tty_output_lock);
}

uv_stream_init(loop, (uv_stream_t*) tty);
uv_stream_init(loop, (uv_stream_t*) tty, UV_TTY);
uv_connection_init((uv_stream_t*) tty);

tty->type = UV_TTY;
tty->handle = win_handle;
tty->read_line_handle = NULL;
tty->read_line_buffer = uv_null_buf_;
Expand Down
3 changes: 1 addition & 2 deletions src/win/udp.c
Expand Up @@ -123,9 +123,8 @@ static int uv_udp_set_socket(uv_loop_t* loop, uv_udp_t* handle,


int uv_udp_init(uv_loop_t* loop, uv_udp_t* handle) {
uv_handle_init(loop, (uv_handle_t*) handle);
uv__handle_init(loop, (uv_handle_t*) handle, UV_UDP);

handle->type = UV_UDP;
handle->socket = INVALID_SOCKET;
handle->reqs_pending = 0;
handle->activecnt = 0;
Expand Down

0 comments on commit 95e89c6

Please sign in to comment.