]> git.proxmox.com Git - rustc.git/blame - src/libuv/src/win/handle-inl.h
Imported Upstream version 0.7
[rustc.git] / src / libuv / src / win / handle-inl.h
CommitLineData
223e47cc
LB
1/* Copyright Joyent, Inc. and other Node contributors. All rights reserved.
2 *
3 * Permission is hereby granted, free of charge, to any person obtaining a copy
4 * of this software and associated documentation files (the "Software"), to
5 * deal in the Software without restriction, including without limitation the
6 * rights to use, copy, modify, merge, publish, distribute, sublicense, and/or
7 * sell copies of the Software, and to permit persons to whom the Software is
8 * furnished to do so, subject to the following conditions:
9 *
10 * The above copyright notice and this permission notice shall be included in
11 * all copies or substantial portions of the Software.
12 *
13 * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
14 * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
15 * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
16 * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
17 * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING
18 * FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS
19 * IN THE SOFTWARE.
20 */
21
22#ifndef UV_WIN_HANDLE_INL_H_
23#define UV_WIN_HANDLE_INL_H_
24
25#include <assert.h>
26
27#include "uv.h"
28#include "internal.h"
29
30
31#define DECREASE_ACTIVE_COUNT(loop, handle) \
32 do { \
33 if (--(handle)->activecnt == 0 && \
34 !((handle)->flags & UV__HANDLE_CLOSING)) { \
35 uv__handle_stop((handle)); \
36 } \
37 assert((handle)->activecnt >= 0); \
38 } while (0)
39
40
41#define INCREASE_ACTIVE_COUNT(loop, handle) \
42 do { \
43 if ((handle)->activecnt++ == 0) { \
44 uv__handle_start((handle)); \
45 } \
46 assert((handle)->activecnt > 0); \
47 } while (0)
48
49
50#define DECREASE_PENDING_REQ_COUNT(handle) \
51 do { \
52 assert(handle->reqs_pending > 0); \
53 handle->reqs_pending--; \
54 \
55 if (handle->flags & UV__HANDLE_CLOSING && \
56 handle->reqs_pending == 0) { \
57 uv_want_endgame(loop, (uv_handle_t*)handle); \
58 } \
59 } while (0)
60
61
62#define uv__handle_closing(handle) \
63 do { \
64 assert(!((handle)->flags & UV__HANDLE_CLOSING)); \
65 \
66 if (!(((handle)->flags & UV__HANDLE_ACTIVE) && \
67 ((handle)->flags & UV__HANDLE_REF))) \
68 uv__active_handle_add((uv_handle_t*) (handle)); \
69 \
70 (handle)->flags |= UV__HANDLE_CLOSING; \
71 (handle)->flags &= ~UV__HANDLE_ACTIVE; \
72 } while (0)
73
74
75#define uv__handle_close(handle) \
76 do { \
77 ngx_queue_remove(&(handle)->handle_queue); \
78 uv__active_handle_rm((uv_handle_t*) (handle)); \
79 \
80 (handle)->flags |= UV_HANDLE_CLOSED; \
81 \
82 if ((handle)->close_cb) \
83 (handle)->close_cb((uv_handle_t*) (handle)); \
84 } while (0)
85
86
87INLINE static void uv_want_endgame(uv_loop_t* loop, uv_handle_t* handle) {
88 if (!(handle->flags & UV_HANDLE_ENDGAME_QUEUED)) {
89 handle->flags |= UV_HANDLE_ENDGAME_QUEUED;
90
91 handle->endgame_next = loop->endgame_handles;
92 loop->endgame_handles = handle;
93 }
94}
95
96
97INLINE static void uv_process_endgames(uv_loop_t* loop) {
98 uv_handle_t* handle;
99
100 while (loop->endgame_handles) {
101 handle = loop->endgame_handles;
102 loop->endgame_handles = handle->endgame_next;
103
104 handle->flags &= ~UV_HANDLE_ENDGAME_QUEUED;
105
106 switch (handle->type) {
107 case UV_TCP:
108 uv_tcp_endgame(loop, (uv_tcp_t*) handle);
109 break;
110
111 case UV_NAMED_PIPE:
112 uv_pipe_endgame(loop, (uv_pipe_t*) handle);
113 break;
114
115 case UV_TTY:
116 uv_tty_endgame(loop, (uv_tty_t*) handle);
117 break;
118
119 case UV_UDP:
120 uv_udp_endgame(loop, (uv_udp_t*) handle);
121 break;
122
123 case UV_POLL:
124 uv_poll_endgame(loop, (uv_poll_t*) handle);
125 break;
126
127 case UV_TIMER:
128 uv_timer_endgame(loop, (uv_timer_t*) handle);
129 break;
130
131 case UV_PREPARE:
132 case UV_CHECK:
133 case UV_IDLE:
134 uv_loop_watcher_endgame(loop, handle);
135 break;
136
137 case UV_ASYNC:
138 uv_async_endgame(loop, (uv_async_t*) handle);
139 break;
140
141 case UV_SIGNAL:
142 uv_signal_endgame(loop, (uv_signal_t*) handle);
143 break;
144
145 case UV_PROCESS:
146 uv_process_endgame(loop, (uv_process_t*) handle);
147 break;
148
149 case UV_FS_EVENT:
150 uv_fs_event_endgame(loop, (uv_fs_event_t*) handle);
151 break;
152
153 case UV_FS_POLL:
154 uv__fs_poll_endgame(loop, (uv_fs_poll_t*) handle);
155 break;
156
157 default:
158 assert(0);
159 break;
160 }
161 }
162}
163
164#endif /* UV_WIN_HANDLE_INL_H_ */