Permalink
Browse files

iocp funnel test

  • Loading branch information...
1 parent 4c63f55 commit 8cd362b4f9e6cd3782c10139ae8673f8604246aa @piscisaureus piscisaureus committed Aug 11, 2011
Showing with 66 additions and 0 deletions.
  1. +61 −0 src/win/core.c
  2. +5 −0 src/win/internal.h
View
@@ -35,13 +35,60 @@
uv_loop_t uv_main_loop_;
+#ifdef IOCP_FUNNEL
+static DWORD WINAPI iocp_funnel_pump(void* arg) {
+ BOOL success;
+ DWORD bytes;
+ ULONG_PTR key;
+ OVERLAPPED* overlapped;
+
+ for (;;) {
+ success = GetQueuedCompletionStatus(LOOP->iocp,
+ &bytes,
+ &key,
+ &overlapped,
+ INFINITE);
+
+ if (overlapped) {
+ if (!success) {
+ overlapped->Internal = GetLastError();
+ } else {
+ overlapped->Internal = 0;
+ }
+
+ if (!PostQueuedCompletionStatus(LOOP->iocp2,
+ bytes,
+ key,
+ overlapped)) {
+ return 0;
+ }
+
+ } else {
+ return 0;
+ }
+ }
+}
+#endif
+
+
static void uv_loop_init() {
/* Create an I/O completion port */
LOOP->iocp = CreateIoCompletionPort(INVALID_HANDLE_VALUE, NULL, 0, 1);
if (LOOP->iocp == NULL) {
uv_fatal_error(GetLastError(), "CreateIoCompletionPort");
}
+#ifdef IOCP_FUNNEL
+ LOOP->iocp2 = CreateIoCompletionPort(INVALID_HANDLE_VALUE, NULL, 0, 1);
+ if (LOOP->iocp2 == NULL) {
+ uv_fatal_error(GetLastError(), "CreateIoCompletionPort");
+ }
+
+ if (NULL == CreateThread(NULL, 0, iocp_funnel_pump, NULL, 0, NULL)) {
+ uv_fatal_error(GetLastError(), "CreateThread");
+ }
+#endif
+
LOOP->refs = 0;
uv_update_time();
@@ -101,19 +148,33 @@ static void uv_poll(int block) {
timeout = 0;
}
+#ifdef IOCP_FUNNEL
+ success = GetQueuedCompletionStatus(LOOP->iocp2,
+ &bytes,
+ &key,
+ &overlapped,
+ timeout);
+#else
success = GetQueuedCompletionStatus(LOOP->iocp,
&bytes,
&key,
&overlapped,
timeout);
+#endif
if (overlapped) {
/* Package was dequeued */
req = uv_overlapped_to_req(overlapped);
+#ifdef IOCP_FUNNEL
+ if (overlapped->Internal) {
+ req->error = uv_new_sys_error(overlapped->Internal);
+ }
+#else
if (!success) {
req->error = uv_new_sys_error(GetLastError());
}
+#endif
uv_insert_pending_req(req);
View
@@ -28,6 +28,8 @@
#include "tree.h"
#include "ntdll.h"
+//#undef IOCP_FUNNEL
+#define IOCP_FUNNEL 1
/*
* Timers
@@ -49,6 +51,9 @@ void uv_process_timers();
typedef struct uv_loop_s {
/* The loop's I/O completion port */
HANDLE iocp;
+#ifdef IOCP_FUNNEL
+ HANDLE iocp2;
+#endif
/* Reference count that keeps the event loop alive */
int refs;
/* The current time according to the event loop. in msecs. */

0 comments on commit 8cd362b

Please sign in to comment.