0
0
mirror of https://github.com/zeromq/libzmq.git synced 2024-12-27 15:41:05 +08:00

Fix up threading code from port tests to windows.

This commit is contained in:
Richard Newton 2013-08-17 14:23:22 +01:00
parent 7f74fc7c99
commit a83baa9b0b
7 changed files with 18 additions and 24 deletions

View File

@ -43,6 +43,8 @@ extern "C" {
# endif # endif
#endif #endif
typedef void (zmq_thread_fn) (void*);
/* Helper functions are used by perf tests so that they don't have to care */ /* Helper functions are used by perf tests so that they don't have to care */
/* about minutiae of time-related functions on different OS platforms. */ /* about minutiae of time-related functions on different OS platforms. */
@ -57,7 +59,7 @@ ZMQ_EXPORT unsigned long zmq_stopwatch_stop (void *watch_);
ZMQ_EXPORT void zmq_sleep (int seconds_); ZMQ_EXPORT void zmq_sleep (int seconds_);
/* Start a thread. Returns a handle to the thread. */ /* Start a thread. Returns a handle to the thread. */
ZMQ_EXPORT void *zmq_threadstart(void* func, void* arg); ZMQ_EXPORT void *zmq_threadstart(zmq_thread_fn* func, void* arg);
/* Wait for thread to complete then free up resources. */ /* Wait for thread to complete then free up resources. */
ZMQ_EXPORT void zmq_threadclose(void* thread); ZMQ_EXPORT void zmq_threadclose(void* thread);

View File

@ -59,10 +59,10 @@ unsigned long zmq_stopwatch_stop (void *watch_)
return (unsigned long) (end - start); return (unsigned long) (end - start);
} }
void *zmq_threadstart(void* func, void* arg) void *zmq_threadstart(zmq_thread_fn* func, void* arg)
{ {
zmq::thread_t* thread = new zmq::thread_t; zmq::thread_t* thread = new zmq::thread_t;
thread->start(static_cast<zmq::thread_fn*>(func), arg); thread->start(func, arg);
return thread; return thread;
} }

View File

@ -66,7 +66,7 @@ static bool read_msg(void* s, zmq_event_t& event, std::string& ep)
// REQ socket monitor thread // REQ socket monitor thread
static void *req_socket_monitor (void *ctx) static void req_socket_monitor (void *ctx)
{ {
zmq_event_t event; zmq_event_t event;
std::string ep ; std::string ep ;
@ -104,11 +104,10 @@ static void *req_socket_monitor (void *ctx)
} }
} }
zmq_close (s); zmq_close (s);
return NULL;
} }
// 2nd REQ socket monitor thread // 2nd REQ socket monitor thread
static void *req2_socket_monitor (void *ctx) static void req2_socket_monitor (void *ctx)
{ {
zmq_event_t event; zmq_event_t event;
std::string ep ; std::string ep ;
@ -133,11 +132,10 @@ static void *req2_socket_monitor (void *ctx)
} }
} }
zmq_close (s); zmq_close (s);
return NULL;
} }
// REP socket monitor thread // REP socket monitor thread
static void *rep_socket_monitor (void *ctx) static void rep_socket_monitor (void *ctx)
{ {
zmq_event_t event; zmq_event_t event;
std::string ep ; std::string ep ;
@ -174,7 +172,6 @@ static void *rep_socket_monitor (void *ctx)
} }
} }
zmq_close (s); zmq_close (s);
return NULL;
} }
int main (void) int main (void)
@ -208,7 +205,7 @@ int main (void)
// REP socket monitor, all events // REP socket monitor, all events
rc = zmq_socket_monitor (rep, "inproc://monitor.rep", ZMQ_EVENT_ALL); rc = zmq_socket_monitor (rep, "inproc://monitor.rep", ZMQ_EVENT_ALL);
assert (rc == 0); assert (rc == 0);
threads [0] = zmq_threadstart(rep_socket_monitor, ctx); threads [0] = zmq_threadstart(&rep_socket_monitor, ctx);
// REQ socket // REQ socket
req = zmq_socket (ctx, ZMQ_REQ); req = zmq_socket (ctx, ZMQ_REQ);
@ -217,7 +214,7 @@ int main (void)
// REQ socket monitor, all events // REQ socket monitor, all events
rc = zmq_socket_monitor (req, "inproc://monitor.req", ZMQ_EVENT_ALL); rc = zmq_socket_monitor (req, "inproc://monitor.req", ZMQ_EVENT_ALL);
assert (rc == 0); assert (rc == 0);
threads [1] = zmq_threadstart(req_socket_monitor, ctx); threads [1] = zmq_threadstart(&req_socket_monitor, ctx);
zmq_sleep(1); zmq_sleep(1);
// Bind REQ and REP // Bind REQ and REP
@ -236,7 +233,7 @@ int main (void)
// 2nd REQ socket monitor, connected event only // 2nd REQ socket monitor, connected event only
rc = zmq_socket_monitor (req2, "inproc://monitor.req2", ZMQ_EVENT_CONNECTED); rc = zmq_socket_monitor (req2, "inproc://monitor.req2", ZMQ_EVENT_CONNECTED);
assert (rc == 0); assert (rc == 0);
threads [2] = zmq_threadstart(req2_socket_monitor, ctx); threads [2] = zmq_threadstart(&req2_socket_monitor, ctx);
rc = zmq_connect (req2, addr.c_str()); rc = zmq_connect (req2, addr.c_str());
assert (rc == 0); assert (rc == 0);

View File

@ -22,8 +22,7 @@
#include <stdlib.h> #include <stdlib.h>
#include "testutil.hpp" #include "testutil.hpp"
static void * static void zap_handler (void *zap)
zap_handler (void *zap)
{ {
char *version = s_recv (zap); char *version = s_recv (zap);
char *sequence = s_recv (zap); char *sequence = s_recv (zap);
@ -62,8 +61,6 @@ zap_handler (void *zap)
int rc = zmq_close (zap); int rc = zmq_close (zap);
assert (rc == 0); assert (rc == 0);
return NULL;
} }
int main (void) int main (void)

View File

@ -23,8 +23,7 @@
#include <stdlib.h> #include <stdlib.h>
#include "testutil.hpp" #include "testutil.hpp"
static void * static void zap_handler (void *zap)
zap_handler (void *zap)
{ {
char *version = s_recv (zap); char *version = s_recv (zap);
char *sequence = s_recv (zap); char *sequence = s_recv (zap);
@ -52,8 +51,6 @@ zap_handler (void *zap)
int rc = zmq_close (zap); int rc = zmq_close (zap);
assert (rc == 0); assert (rc == 0);
return NULL;
} }
int main (void) int main (void)

View File

@ -27,7 +27,7 @@
extern "C" extern "C"
{ {
static void *worker (void *s) static void worker (void *s)
{ {
int rc; int rc;
@ -37,8 +37,6 @@ extern "C"
// Start closing the socket while the connecting process is underway. // Start closing the socket while the connecting process is underway.
rc = zmq_close (s); rc = zmq_close (s);
assert (rc == 0); assert (rc == 0);
return NULL;
} }
} }
@ -68,7 +66,7 @@ int main (void)
for (i = 0; i != THREAD_COUNT; i++) { for (i = 0; i != THREAD_COUNT; i++) {
s2 = zmq_socket (ctx, ZMQ_SUB); s2 = zmq_socket (ctx, ZMQ_SUB);
assert (s2); assert (s2);
threads [i] = zmq_threadstart(worker, s2); threads [i] = zmq_threadstart(&worker, s2);
} }
for (i = 0; i != THREAD_COUNT; i++) { for (i = 0; i != THREAD_COUNT; i++) {

View File

@ -28,6 +28,7 @@
#include <stdarg.h> #include <stdarg.h>
#if defined _WIN32 #if defined _WIN32
#include <crtdbg.h>
#pragma warning(disable:4996) #pragma warning(disable:4996)
#endif #endif
@ -200,6 +201,8 @@ void setup_test_environment()
{ {
#if defined _WIN32 #if defined _WIN32
_set_abort_behavior( 0, _WRITE_ABORT_MSG); _set_abort_behavior( 0, _WRITE_ABORT_MSG);
_CrtSetReportMode( _CRT_ASSERT, _CRTDBG_MODE_FILE );
_CrtSetReportFile( _CRT_ASSERT, _CRTDBG_FILE_STDERR );
#endif #endif
} }