Windows: make the refcount tests pass

This commit is contained in:
Bert Belder 2012-03-09 04:52:48 +01:00
parent 18823270aa
commit 95296dfa3c
6 changed files with 29 additions and 13 deletions

View File

@ -179,7 +179,7 @@ void uv_want_endgame(uv_loop_t* loop, uv_handle_t* handle) {
void uv_process_endgames(uv_loop_t* loop) {
uv_handle_t* handle;
while (loop->endgame_handles) {
while (loop->endgame_handles && loop->refs > 0) {
handle = loop->endgame_handles;
loop->endgame_handles = handle->endgame_next;

View File

@ -300,6 +300,7 @@ void uv_pipe_endgame(uv_loop_t* loop, uv_pipe_t* handle) {
uv__set_sys_error(loop, pRtlNtStatusToDosError(nt_status));
req->cb(req, -1);
}
uv_unref(loop);
DECREASE_PENDING_REQ_COUNT(handle);
return;
}
@ -328,6 +329,7 @@ void uv_pipe_endgame(uv_loop_t* loop, uv_pipe_t* handle) {
uv__set_sys_error(loop, GetLastError());
req->cb(req, -1);
}
uv_unref(loop);
DECREASE_PENDING_REQ_COUNT(handle);
return;
}
@ -556,6 +558,7 @@ void uv_pipe_connect(uv_connect_t* req, uv_pipe_t* handle,
goto error;
}
uv_ref(loop);
handle->reqs_pending++;
return;
@ -578,6 +581,7 @@ void uv_pipe_connect(uv_connect_t* req, uv_pipe_t* handle,
SET_REQ_SUCCESS(req);
uv_insert_pending_req(loop, (uv_req_t*) req);
handle->reqs_pending++;
uv_ref(loop);
return;
error:
@ -594,6 +598,7 @@ error:
SET_REQ_ERROR(req, errno);
uv_insert_pending_req(loop, (uv_req_t*) req);
handle->reqs_pending++;
uv_ref(loop);
return;
}
@ -1132,10 +1137,7 @@ static int uv_pipe_write_impl(uv_loop_t* loop, uv_write_t* req,
handle->write_queue_size += req->queued_bytes;
}
if (handle->write_reqs_pending == 0) {
uv_ref(loop);
}
uv_ref(loop);
handle->reqs_pending++;
handle->write_reqs_pending++;
@ -1190,10 +1192,7 @@ static int uv_pipe_write_impl(uv_loop_t* loop, uv_write_t* req,
}
}
if (handle->write_reqs_pending == 0) {
uv_ref(loop);
}
uv_ref(loop);
handle->reqs_pending++;
handle->write_reqs_pending++;
@ -1449,15 +1448,12 @@ void uv_process_pipe_write_req(uv_loop_t* loop, uv_pipe_t* handle,
uv_queue_non_overlapped_write(handle);
}
if (handle->write_reqs_pending == 0) {
uv_unref(loop);
}
if (handle->write_reqs_pending == 0 &&
handle->flags & UV_HANDLE_SHUTTING) {
uv_want_endgame(loop, (uv_handle_t*)handle);
}
uv_unref(loop);
DECREASE_PENDING_REQ_COUNT(handle);
}
@ -1504,6 +1500,7 @@ void uv_process_pipe_connect_req(uv_loop_t* loop, uv_pipe_t* handle,
}
}
uv_unref(loop);
DECREASE_PENDING_REQ_COUNT(handle);
}
@ -1528,6 +1525,7 @@ void uv_process_pipe_shutdown_req(uv_loop_t* loop, uv_pipe_t* handle,
req->cb(req, 0);
}
uv_unref(loop);
DECREASE_PENDING_REQ_COUNT(handle);
}
@ -1543,6 +1541,7 @@ static void eof_timer_init(uv_pipe_t* pipe) {
r = uv_timer_init(pipe->loop, pipe->eof_timer);
assert(r == 0); /* timers can't fail */
pipe->eof_timer->data = pipe;
uv_unref(pipe->loop);
}
@ -1605,6 +1604,7 @@ static void eof_timer_destroy(uv_pipe_t* pipe) {
assert(pipe->flags && UV_HANDLE_CONNECTION);
if (pipe->eof_timer) {
uv_ref(pipe->loop);
uv_close((uv_handle_t*) pipe->eof_timer, eof_timer_close_cb);
pipe->eof_timer = NULL;
}

View File

@ -169,6 +169,7 @@ int uv_shutdown(uv_shutdown_t* req, uv_stream_t* handle, uv_shutdown_cb cb) {
handle->flags |= UV_HANDLE_SHUTTING;
handle->shutdown_req = req;
handle->reqs_pending++;
uv_ref(loop);
uv_want_endgame(loop, (uv_handle_t*)handle);

View File

@ -189,6 +189,7 @@ void uv_tcp_endgame(uv_loop_t* loop, uv_tcp_t* handle) {
handle->shutdown_req->cb(handle->shutdown_req, status);
}
uv_unref(loop);
DECREASE_PENDING_REQ_COUNT(handle);
return;
}
@ -643,10 +644,12 @@ int uv__tcp_connect(uv_connect_t* req,
if (UV_SUCCEEDED_WITHOUT_IOCP(success)) {
/* Process the req without IOCP. */
handle->reqs_pending++;
uv_ref(loop);
uv_insert_pending_req(loop, (uv_req_t*)req);
} else if (UV_SUCCEEDED_WITH_IOCP(success)) {
/* The req will be processed with IOCP. */
handle->reqs_pending++;
uv_ref(loop);
} else {
uv__set_sys_error(loop, WSAGetLastError());
return -1;
@ -702,9 +705,11 @@ int uv__tcp_connect6(uv_connect_t* req,
if (UV_SUCCEEDED_WITHOUT_IOCP(success)) {
handle->reqs_pending++;
uv_ref(loop);
uv_insert_pending_req(loop, (uv_req_t*)req);
} else if (UV_SUCCEEDED_WITH_IOCP(success)) {
handle->reqs_pending++;
uv_ref(loop);
} else {
uv__set_sys_error(loop, WSAGetLastError());
return -1;
@ -799,12 +804,14 @@ int uv_tcp_write(uv_loop_t* loop, uv_write_t* req, uv_tcp_t* handle,
handle->reqs_pending++;
handle->write_reqs_pending++;
uv_insert_pending_req(loop, (uv_req_t*) req);
uv_ref(loop);
} else if (UV_SUCCEEDED_WITH_IOCP(result == 0)) {
/* Request queued by the kernel. */
req->queued_bytes = uv_count_bufs(bufs, bufcnt);
handle->reqs_pending++;
handle->write_reqs_pending++;
handle->write_queue_size += req->queued_bytes;
uv_ref(loop);
} else {
/* Send failed due to an error. */
uv__set_sys_error(loop, WSAGetLastError());
@ -950,6 +957,7 @@ void uv_process_tcp_write_req(uv_loop_t* loop, uv_tcp_t* handle,
}
DECREASE_PENDING_REQ_COUNT(handle);
uv_unref(loop);
}
@ -1024,6 +1032,7 @@ void uv_process_tcp_connect_req(uv_loop_t* loop, uv_tcp_t* handle,
}
DECREASE_PENDING_REQ_COUNT(handle);
uv_unref(loop);
}

View File

@ -1683,6 +1683,7 @@ int uv_tty_write(uv_loop_t* loop, uv_write_t* req, uv_tty_t* handle,
handle->reqs_pending++;
handle->write_reqs_pending++;
uv_ref(loop);
req->queued_bytes = 0;
@ -1715,6 +1716,7 @@ void uv_process_tty_write_req(uv_loop_t* loop, uv_tty_t* handle,
}
DECREASE_PENDING_REQ_COUNT(handle);
uv_unref(loop);
}
@ -1740,6 +1742,7 @@ void uv_tty_endgame(uv_loop_t* loop, uv_tty_t* handle) {
handle->shutdown_req->cb(handle->shutdown_req, 0);
}
uv_unref(loop);
DECREASE_PENDING_REQ_COUNT(handle);
return;
}

View File

@ -404,11 +404,13 @@ static int uv__udp_send(uv_udp_send_t* req, uv_udp_t* handle, uv_buf_t bufs[],
/* Request completed immediately. */
req->queued_bytes = 0;
handle->reqs_pending++;
uv_ref(loop);
uv_insert_pending_req(loop, (uv_req_t*)req);
} else if (UV_SUCCEEDED_WITH_IOCP(result == 0)) {
/* Request queued by the kernel. */
req->queued_bytes = uv_count_bufs(bufs, bufcnt);
handle->reqs_pending++;
uv_ref(loop);
} else {
/* Send failed due to an error. */
uv__set_sys_error(loop, WSAGetLastError());
@ -573,6 +575,7 @@ void uv_process_udp_send_req(uv_loop_t* loop, uv_udp_t* handle,
}
}
uv_unref(loop);
DECREASE_PENDING_REQ_COUNT(handle);
}