diff options
Diffstat (limited to 'perf')
-rw-r--r-- | perf/inproc_lat.cpp | 46 | ||||
-rw-r--r-- | perf/inproc_thr.cpp | 46 |
2 files changed, 88 insertions, 4 deletions
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 <stdio.h> #include <stdlib.h> #include <string.h> + +#include "../src/platform.hpp" + +#if defined ZMQ_HAVE_WINDOWS +#include <windows.h> +#include <process.h> +#else #include <pthread.h> +#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 <stdio.h> #include <stdlib.h> #include <string.h> + +#include "../src/platform.hpp" + +#if defined ZMQ_HAVE_WINDOWS +#include <windows.h> +#include <process.h> +#else #include <pthread.h> +#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) { |