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

Commit

Permalink
windows: inline a couple of handle functions
Browse files Browse the repository at this point in the history
  • Loading branch information
piscisaureus committed Jun 2, 2012
1 parent d402604 commit d8b95ea
Show file tree
Hide file tree
Showing 16 changed files with 119 additions and 87 deletions.
1 change: 1 addition & 0 deletions src/win/async.c
Expand Up @@ -23,6 +23,7 @@

#include "uv.h"
#include "internal.h"
#include "handle-inl.h"
#include "req-inl.h"


Expand Down
1 change: 1 addition & 0 deletions src/win/core.c
Expand Up @@ -28,6 +28,7 @@

#include "uv.h"
#include "internal.h"
#include "handle-inl.h"
#include "req-inl.h"


Expand Down
1 change: 1 addition & 0 deletions src/win/fs-event.c
Expand Up @@ -27,6 +27,7 @@

#include "uv.h"
#include "internal.h"
#include "handle-inl.h"
#include "req-inl.h"


Expand Down
104 changes: 104 additions & 0 deletions src/win/handle-inl.h
@@ -0,0 +1,104 @@
/* 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"


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;

handle->endgame_next = loop->endgame_handles;
loop->endgame_handles = handle;
}
}


INLINE static void uv_process_endgames(uv_loop_t* loop) {
uv_handle_t* handle;

while (loop->endgame_handles) {
handle = loop->endgame_handles;
loop->endgame_handles = handle->endgame_next;

handle->flags &= ~UV_HANDLE_ENDGAME_QUEUED;

switch (handle->type) {
case UV_TCP:
uv_tcp_endgame(loop, (uv_tcp_t*) handle);
break;

case UV_NAMED_PIPE:
uv_pipe_endgame(loop, (uv_pipe_t*) handle);
break;

case UV_TTY:
uv_tty_endgame(loop, (uv_tty_t*) handle);
break;

case UV_UDP:
uv_udp_endgame(loop, (uv_udp_t*) handle);
break;

case UV_POLL:
uv_poll_endgame(loop, (uv_poll_t*) handle);
break;

case UV_TIMER:
uv_timer_endgame(loop, (uv_timer_t*) handle);
break;

case UV_PREPARE:
case UV_CHECK:
case UV_IDLE:
uv_loop_watcher_endgame(loop, handle);
break;

case UV_ASYNC:
uv_async_endgame(loop, (uv_async_t*) handle);
break;

case UV_PROCESS:
uv_process_endgame(loop, (uv_process_t*) handle);
break;

case UV_FS_EVENT:
uv_fs_event_endgame(loop, (uv_fs_event_t*) handle);
break;

default:
assert(0);
break;
}
}
}
80 changes: 1 addition & 79 deletions src/win/handle.c
Expand Up @@ -24,6 +24,7 @@

#include "uv.h"
#include "internal.h"
#include "handle-inl.h"


uv_handle_type uv_guess_handle(uv_file file) {
Expand Down Expand Up @@ -62,15 +63,6 @@ int uv_is_active(const uv_handle_t* handle) {
}


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++;
}


void uv_close(uv_handle_t* handle, uv_close_cb cb) {
uv_loop_t* loop = handle->loop;

Expand Down Expand Up @@ -150,73 +142,3 @@ void uv_close(uv_handle_t* handle, uv_close_cb cb) {
int uv_is_closing(const uv_handle_t* handle) {
return handle->flags & (UV_HANDLE_CLOSING | UV_HANDLE_CLOSED);
}


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;

handle->endgame_next = loop->endgame_handles;
loop->endgame_handles = handle;
}
}


void uv_process_endgames(uv_loop_t* loop) {
uv_handle_t* handle;

while (loop->endgame_handles) {
handle = loop->endgame_handles;
loop->endgame_handles = handle->endgame_next;

handle->flags &= ~UV_HANDLE_ENDGAME_QUEUED;

switch (handle->type) {
case UV_TCP:
uv_tcp_endgame(loop, (uv_tcp_t*) handle);
break;

case UV_NAMED_PIPE:
uv_pipe_endgame(loop, (uv_pipe_t*) handle);
break;

case UV_TTY:
uv_tty_endgame(loop, (uv_tty_t*) handle);
break;

case UV_UDP:
uv_udp_endgame(loop, (uv_udp_t*) handle);
break;

case UV_POLL:
uv_poll_endgame(loop, (uv_poll_t*) handle);
break;

case UV_TIMER:
uv_timer_endgame(loop, (uv_timer_t*) handle);
break;

case UV_PREPARE:
case UV_CHECK:
case UV_IDLE:
uv_loop_watcher_endgame(loop, handle);
break;

case UV_ASYNC:
uv_async_endgame(loop, (uv_async_t*) handle);
break;

case UV_PROCESS:
uv_process_endgame(loop, (uv_process_t*) handle);
break;

case UV_FS_EVENT:
uv_fs_event_endgame(loop, (uv_fs_event_t*) handle);
break;

default:
assert(0);
break;
}
}
}
9 changes: 1 addition & 8 deletions src/win/internal.h
Expand Up @@ -32,6 +32,7 @@

/*
* Handles
* (also see handle-inl.h)
*/

/* Used by all handles. */
Expand Down Expand Up @@ -81,9 +82,6 @@
#define UV_HANDLE_POLL_SLOW 0x02000000


void uv_want_endgame(uv_loop_t* loop, uv_handle_t* handle);
void uv_process_endgames(uv_loop_t* loop);

#define DECREASE_PENDING_REQ_COUNT(handle) \
do { \
assert(handle->reqs_pending > 0); \
Expand Down Expand Up @@ -139,11 +137,6 @@ void uv_process_endgames(uv_loop_t* loop);
} \
} while (0)

/*
* Handles
*/
void uv_handle_init(uv_loop_t* loop, uv_handle_t* handle);


/*
* Requests (also see req-inl.h)
Expand Down
1 change: 1 addition & 0 deletions src/win/loop-watcher.c
Expand Up @@ -23,6 +23,7 @@

#include "uv.h"
#include "internal.h"
#include "handle-inl.h"


void uv_loop_watcher_endgame(uv_loop_t* loop, uv_handle_t* handle) {
Expand Down
1 change: 1 addition & 0 deletions src/win/pipe.c
Expand Up @@ -26,6 +26,7 @@

#include "uv.h"
#include "internal.h"
#include "handle-inl.h"
#include "req-inl.h"


Expand Down
1 change: 1 addition & 0 deletions src/win/poll.c
Expand Up @@ -24,6 +24,7 @@

#include "uv.h"
#include "internal.h"
#include "handle-inl.h"
#include "req-inl.h"


Expand Down
1 change: 1 addition & 0 deletions src/win/process.c
Expand Up @@ -27,6 +27,7 @@

#include "uv.h"
#include "internal.h"
#include "handle-inl.h"
#include "req-inl.h"


Expand Down
1 change: 1 addition & 0 deletions src/win/stream.c
Expand Up @@ -23,6 +23,7 @@

#include "uv.h"
#include "internal.h"
#include "handle-inl.h"
#include "req-inl.h"


Expand Down
1 change: 1 addition & 0 deletions src/win/tcp.c
Expand Up @@ -23,6 +23,7 @@

#include "uv.h"
#include "internal.h"
#include "handle-inl.h"
#include "req-inl.h"


Expand Down
1 change: 1 addition & 0 deletions src/win/timer.c
Expand Up @@ -25,6 +25,7 @@
#include "uv.h"
#include "internal.h"
#include "tree.h"
#include "handle-inl.h"


void uv_update_time(uv_loop_t* loop) {
Expand Down
1 change: 1 addition & 0 deletions src/win/tty.c
Expand Up @@ -26,6 +26,7 @@

#include "uv.h"
#include "internal.h"
#include "handle-inl.h"
#include "req-inl.h"


Expand Down
1 change: 1 addition & 0 deletions src/win/udp.c
Expand Up @@ -23,6 +23,7 @@

#include "uv.h"
#include "internal.h"
#include "handle-inl.h"
#include "req-inl.h"


Expand Down
1 change: 1 addition & 0 deletions uv.gyp
Expand Up @@ -142,6 +142,7 @@
'src/win/fs-event.c',
'src/win/getaddrinfo.c',
'src/win/handle.c',
'src/win/handle-inl.h',
'src/win/internal.h',
'src/win/loop-watcher.c',
'src/win/pipe.c',
Expand Down

0 comments on commit d8b95ea

Please sign in to comment.