From 85c2a84036675d40af47b57c410309da04ef742b Mon Sep 17 00:00:00 2001 From: Martin Sustrik Date: Sat, 2 Apr 2011 09:50:35 +0200 Subject: inproc perf tests now work on Windows Signed-off-by: Martin Sustrik --- perf/inproc_lat.cpp | 46 ++++++++++++++++++++++++++++++++++++++++++++-- perf/inproc_thr.cpp | 46 ++++++++++++++++++++++++++++++++++++++++++++-- 2 files changed, 88 insertions(+), 4 deletions(-) (limited to 'perf') diff --git a/perf/inproc_lat.cpp b/perf/inproc_lat.cpp index f4e0eaa..ea4b5b1 100644 --- a/perf/inproc_lat.cpp +++ b/perf/inproc_lat.cpp @@ -24,19 +24,31 @@ #include #include #include + +#include "../src/platform.hpp" + +#if defined ZMQ_HAVE_WINDOWS +#include +#include +#else #include +#endif static size_t message_size; static int roundtrip_count; -static void *worker (void *ctx) +#if defined ZMQ_HAVE_WINDOWS +static unsigned int __stdcall worker (void *ctx_) +#else +static void *worker (void *ctx_) +#endif { void *s; int rc; int i; zmq_msg_t msg; - s = zmq_socket (ctx, ZMQ_REP); + s = zmq_socket (ctx_, ZMQ_REP); if (!s) { printf ("error in zmq_socket: %s\n", zmq_strerror (errno)); exit (1); @@ -79,12 +91,20 @@ static void *worker (void *ctx) exit (1); } +#if defined ZMQ_HAVE_WINDOWS + return 0; +#else return NULL; +#endif } int main (int argc, char *argv []) { +#if defined ZMQ_HAVE_WINDOWS + HANDLE local_thread; +#else pthread_t local_thread; +#endif void *ctx; void *s; int rc; @@ -120,11 +140,20 @@ int main (int argc, char *argv []) return -1; } +#if defined ZMQ_HAVE_WINDOWS + local_thread = (HANDLE) _beginthreadex (NULL, 0, + worker, ctx, 0 , NULL); + if (local_thread == 0) { + printf ("error in _beginthreadex\n"); + return -1; + } +#else rc = pthread_create (&local_thread, NULL, worker, ctx); if (rc != 0) { printf ("error in pthread_create: %s\n", zmq_strerror (rc)); return -1; } +#endif rc = zmq_msg_init_size (&msg, message_size); if (rc != 0) { @@ -165,11 +194,24 @@ int main (int argc, char *argv []) latency = (double) elapsed / (roundtrip_count * 2); +#if defined ZMQ_HAVE_WINDOWS + DWORD rc2 = WaitForSingleObject (local_thread, INFINITE); + if (rc == WAIT_FAILED) { + printf ("error in WaitForSingleObject\n"); + return -1; + } + BOOL rc3 = CloseHandle (local_thread); + if (rc3 == 0) { + printf ("error in CloseHandle\n"); + return -1; + } +#else rc = pthread_join (local_thread, NULL); if (rc != 0) { printf ("error in pthread_join: %s\n", zmq_strerror (rc)); return -1; } +#endif printf ("average latency: %.3f [us]\n", (double) latency); diff --git a/perf/inproc_thr.cpp b/perf/inproc_thr.cpp index 57a5019..127257c 100644 --- a/perf/inproc_thr.cpp +++ b/perf/inproc_thr.cpp @@ -24,19 +24,31 @@ #include #include #include + +#include "../src/platform.hpp" + +#if defined ZMQ_HAVE_WINDOWS +#include +#include +#else #include +#endif static int message_count; static size_t message_size; -static void *worker (void *ctx) +#if defined ZMQ_HAVE_WINDOWS +static unsigned int __stdcall worker (void *ctx_) +#else +static void *worker (void *ctx_) +#endif { void *s; int rc; int i; zmq_msg_t msg; - s = zmq_socket (ctx, ZMQ_PUB); + s = zmq_socket (ctx_, ZMQ_PUB); if (!s) { printf ("error in zmq_socket: %s\n", zmq_strerror (errno)); exit (1); @@ -77,12 +89,20 @@ static void *worker (void *ctx) exit (1); } +#if defined ZMQ_HAVE_WINDOWS + return 0; +#else return NULL; +#endif } int main (int argc, char *argv []) { +#if defined ZMQ_HAVE_WINDOWS + HANDLE local_thread; +#else pthread_t local_thread; +#endif void *ctx; void *s; int rc; @@ -125,11 +145,20 @@ int main (int argc, char *argv []) return -1; } +#if defined ZMQ_HAVE_WINDOWS + local_thread = (HANDLE) _beginthreadex (NULL, 0, + worker, ctx, 0 , NULL); + if (local_thread == 0) { + printf ("error in _beginthreadex\n"); + return -1; + } +#else rc = pthread_create (&local_thread, NULL, worker, ctx); if (rc != 0) { printf ("error in pthread_create: %s\n", zmq_strerror (rc)); return -1; } +#endif rc = zmq_msg_init (&msg); if (rc != 0) { @@ -174,11 +203,24 @@ int main (int argc, char *argv []) return -1; } +#if defined ZMQ_HAVE_WINDOWS + DWORD rc2 = WaitForSingleObject (local_thread, INFINITE); + if (rc == WAIT_FAILED) { + printf ("error in WaitForSingleObject\n"); + return -1; + } + BOOL rc3 = CloseHandle (local_thread); + if (rc3 == 0) { + printf ("error in CloseHandle\n"); + return -1; + } +#else rc = pthread_join (local_thread, NULL); if (rc != 0) { printf ("error in pthread_join: %s\n", zmq_strerror (rc)); return -1; } +#endif rc = zmq_close (s); if (rc != 0) { -- cgit v1.2.3