From 85c2a84036675d40af47b57c410309da04ef742b Mon Sep 17 00:00:00 2001 From: Martin Sustrik Date: Sat, 2 Apr 2011 09:50:35 +0200 Subject: [PATCH] inproc perf tests now work on Windows Signed-off-by: Martin Sustrik --- builds/msvc/inproc_lat/inproc_lat.vcproj | 174 +++++++++++++++++++++++ builds/msvc/inproc_thr/inproc_thr.vcproj | 174 +++++++++++++++++++++++ builds/msvc/msvc.sln | 22 +++ perf/inproc_lat.cpp | 46 +++++- perf/inproc_thr.cpp | 46 +++++- 5 files changed, 458 insertions(+), 4 deletions(-) create mode 100644 builds/msvc/inproc_lat/inproc_lat.vcproj create mode 100644 builds/msvc/inproc_thr/inproc_thr.vcproj diff --git a/builds/msvc/inproc_lat/inproc_lat.vcproj b/builds/msvc/inproc_lat/inproc_lat.vcproj new file mode 100644 index 00000000..15549ffd --- /dev/null +++ b/builds/msvc/inproc_lat/inproc_lat.vcproj @@ -0,0 +1,174 @@ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + diff --git a/builds/msvc/inproc_thr/inproc_thr.vcproj b/builds/msvc/inproc_thr/inproc_thr.vcproj new file mode 100644 index 00000000..96415c96 --- /dev/null +++ b/builds/msvc/inproc_thr/inproc_thr.vcproj @@ -0,0 +1,174 @@ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + diff --git a/builds/msvc/msvc.sln b/builds/msvc/msvc.sln index 8d72dea0..a79ec654 100644 --- a/builds/msvc/msvc.sln +++ b/builds/msvc/msvc.sln @@ -23,6 +23,16 @@ Project("{8BC9CEB8-8B4A-11D0-8D11-00A0C91BC942}") = "remote_thr", "c_remote_thr\ {641C5F36-32EE-4323-B740-992B651CF9D6} = {641C5F36-32EE-4323-B740-992B651CF9D6} EndProjectSection EndProject +Project("{8BC9CEB8-8B4A-11D0-8D11-00A0C91BC942}") = "inproc_lat", "inproc_lat\inproc_lat.vcproj", "{6FF7436F-B3F6-4AE9-A3AC-CFDE8A3872A0}" + ProjectSection(ProjectDependencies) = postProject + {641C5F36-32EE-4323-B740-992B651CF9D6} = {641C5F36-32EE-4323-B740-992B651CF9D6} + EndProjectSection +EndProject +Project("{8BC9CEB8-8B4A-11D0-8D11-00A0C91BC942}") = "inproc_thr", "inproc_thr\inproc_thr.vcproj", "{1077E977-95DD-4E73-A692-74647DD0CC1E}" + ProjectSection(ProjectDependencies) = postProject + {641C5F36-32EE-4323-B740-992B651CF9D6} = {641C5F36-32EE-4323-B740-992B651CF9D6} + EndProjectSection +EndProject Global GlobalSection(SolutionConfigurationPlatforms) = preSolution Debug|Win32 = Debug|Win32 @@ -60,6 +70,18 @@ Global {B15E059C-0CBB-4A82-8C42-6567FB650802}.Release|Win32.Build.0 = Release|Win32 {B15E059C-0CBB-4A82-8C42-6567FB650802}.WithOpenPGM|Win32.ActiveCfg = Release|Win32 {B15E059C-0CBB-4A82-8C42-6567FB650802}.WithOpenPGM|Win32.Build.0 = Release|Win32 + {6FF7436F-B3F6-4AE9-A3AC-CFDE8A3872A0}.Debug|Win32.ActiveCfg = Debug|Win32 + {6FF7436F-B3F6-4AE9-A3AC-CFDE8A3872A0}.Debug|Win32.Build.0 = Debug|Win32 + {6FF7436F-B3F6-4AE9-A3AC-CFDE8A3872A0}.Release|Win32.ActiveCfg = Release|Win32 + {6FF7436F-B3F6-4AE9-A3AC-CFDE8A3872A0}.Release|Win32.Build.0 = Release|Win32 + {6FF7436F-B3F6-4AE9-A3AC-CFDE8A3872A0}.WithOpenPGM|Win32.ActiveCfg = Release|Win32 + {6FF7436F-B3F6-4AE9-A3AC-CFDE8A3872A0}.WithOpenPGM|Win32.Build.0 = Release|Win32 + {1077E977-95DD-4E73-A692-74647DD0CC1E}.Debug|Win32.ActiveCfg = Debug|Win32 + {1077E977-95DD-4E73-A692-74647DD0CC1E}.Debug|Win32.Build.0 = Debug|Win32 + {1077E977-95DD-4E73-A692-74647DD0CC1E}.Release|Win32.ActiveCfg = Release|Win32 + {1077E977-95DD-4E73-A692-74647DD0CC1E}.Release|Win32.Build.0 = Release|Win32 + {1077E977-95DD-4E73-A692-74647DD0CC1E}.WithOpenPGM|Win32.ActiveCfg = Release|Win32 + {1077E977-95DD-4E73-A692-74647DD0CC1E}.WithOpenPGM|Win32.Build.0 = Release|Win32 EndGlobalSection GlobalSection(SolutionProperties) = preSolution HideSolutionNode = FALSE diff --git a/perf/inproc_lat.cpp b/perf/inproc_lat.cpp index f4e0eaab..ea4b5b1b 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 57a5019e..127257c3 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) {