mirror of
https://github.com/zeromq/libzmq.git
synced 2024-12-13 18:55:10 +01:00
Fix up threading code from port tests to windows.
This commit is contained in:
parent
7f74fc7c99
commit
a83baa9b0b
@ -43,6 +43,8 @@ extern "C" {
|
||||
# endif
|
||||
#endif
|
||||
|
||||
typedef void (zmq_thread_fn) (void*);
|
||||
|
||||
/* 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. */
|
||||
|
||||
@ -57,7 +59,7 @@ ZMQ_EXPORT unsigned long zmq_stopwatch_stop (void *watch_);
|
||||
ZMQ_EXPORT void zmq_sleep (int seconds_);
|
||||
|
||||
/* 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. */
|
||||
ZMQ_EXPORT void zmq_threadclose(void* thread);
|
||||
|
@ -59,10 +59,10 @@ unsigned long zmq_stopwatch_stop (void *watch_)
|
||||
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;
|
||||
thread->start(static_cast<zmq::thread_fn*>(func), arg);
|
||||
thread->start(func, arg);
|
||||
return thread;
|
||||
}
|
||||
|
||||
|
@ -66,7 +66,7 @@ static bool read_msg(void* s, zmq_event_t& event, std::string& ep)
|
||||
|
||||
|
||||
// REQ socket monitor thread
|
||||
static void *req_socket_monitor (void *ctx)
|
||||
static void req_socket_monitor (void *ctx)
|
||||
{
|
||||
zmq_event_t event;
|
||||
std::string ep ;
|
||||
@ -104,11 +104,10 @@ static void *req_socket_monitor (void *ctx)
|
||||
}
|
||||
}
|
||||
zmq_close (s);
|
||||
return NULL;
|
||||
}
|
||||
|
||||
// 2nd REQ socket monitor thread
|
||||
static void *req2_socket_monitor (void *ctx)
|
||||
static void req2_socket_monitor (void *ctx)
|
||||
{
|
||||
zmq_event_t event;
|
||||
std::string ep ;
|
||||
@ -133,11 +132,10 @@ static void *req2_socket_monitor (void *ctx)
|
||||
}
|
||||
}
|
||||
zmq_close (s);
|
||||
return NULL;
|
||||
}
|
||||
|
||||
// REP socket monitor thread
|
||||
static void *rep_socket_monitor (void *ctx)
|
||||
static void rep_socket_monitor (void *ctx)
|
||||
{
|
||||
zmq_event_t event;
|
||||
std::string ep ;
|
||||
@ -174,7 +172,6 @@ static void *rep_socket_monitor (void *ctx)
|
||||
}
|
||||
}
|
||||
zmq_close (s);
|
||||
return NULL;
|
||||
}
|
||||
|
||||
int main (void)
|
||||
@ -208,7 +205,7 @@ int main (void)
|
||||
// REP socket monitor, all events
|
||||
rc = zmq_socket_monitor (rep, "inproc://monitor.rep", ZMQ_EVENT_ALL);
|
||||
assert (rc == 0);
|
||||
threads [0] = zmq_threadstart(rep_socket_monitor, ctx);
|
||||
threads [0] = zmq_threadstart(&rep_socket_monitor, ctx);
|
||||
|
||||
// REQ socket
|
||||
req = zmq_socket (ctx, ZMQ_REQ);
|
||||
@ -217,7 +214,7 @@ int main (void)
|
||||
// REQ socket monitor, all events
|
||||
rc = zmq_socket_monitor (req, "inproc://monitor.req", ZMQ_EVENT_ALL);
|
||||
assert (rc == 0);
|
||||
threads [1] = zmq_threadstart(req_socket_monitor, ctx);
|
||||
threads [1] = zmq_threadstart(&req_socket_monitor, ctx);
|
||||
zmq_sleep(1);
|
||||
|
||||
// Bind REQ and REP
|
||||
@ -236,7 +233,7 @@ int main (void)
|
||||
// 2nd REQ socket monitor, connected event only
|
||||
rc = zmq_socket_monitor (req2, "inproc://monitor.req2", ZMQ_EVENT_CONNECTED);
|
||||
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());
|
||||
assert (rc == 0);
|
||||
|
@ -22,8 +22,7 @@
|
||||
#include <stdlib.h>
|
||||
#include "testutil.hpp"
|
||||
|
||||
static void *
|
||||
zap_handler (void *zap)
|
||||
static void zap_handler (void *zap)
|
||||
{
|
||||
char *version = s_recv (zap);
|
||||
char *sequence = s_recv (zap);
|
||||
@ -62,8 +61,6 @@ zap_handler (void *zap)
|
||||
|
||||
int rc = zmq_close (zap);
|
||||
assert (rc == 0);
|
||||
|
||||
return NULL;
|
||||
}
|
||||
|
||||
int main (void)
|
||||
|
@ -23,8 +23,7 @@
|
||||
#include <stdlib.h>
|
||||
#include "testutil.hpp"
|
||||
|
||||
static void *
|
||||
zap_handler (void *zap)
|
||||
static void zap_handler (void *zap)
|
||||
{
|
||||
char *version = s_recv (zap);
|
||||
char *sequence = s_recv (zap);
|
||||
@ -52,8 +51,6 @@ zap_handler (void *zap)
|
||||
|
||||
int rc = zmq_close (zap);
|
||||
assert (rc == 0);
|
||||
|
||||
return NULL;
|
||||
}
|
||||
|
||||
int main (void)
|
||||
|
@ -27,7 +27,7 @@
|
||||
|
||||
extern "C"
|
||||
{
|
||||
static void *worker (void *s)
|
||||
static void worker (void *s)
|
||||
{
|
||||
int rc;
|
||||
|
||||
@ -37,8 +37,6 @@ extern "C"
|
||||
// Start closing the socket while the connecting process is underway.
|
||||
rc = zmq_close (s);
|
||||
assert (rc == 0);
|
||||
|
||||
return NULL;
|
||||
}
|
||||
}
|
||||
|
||||
@ -68,7 +66,7 @@ int main (void)
|
||||
for (i = 0; i != THREAD_COUNT; i++) {
|
||||
s2 = zmq_socket (ctx, ZMQ_SUB);
|
||||
assert (s2);
|
||||
threads [i] = zmq_threadstart(worker, s2);
|
||||
threads [i] = zmq_threadstart(&worker, s2);
|
||||
}
|
||||
|
||||
for (i = 0; i != THREAD_COUNT; i++) {
|
||||
|
@ -28,6 +28,7 @@
|
||||
#include <stdarg.h>
|
||||
|
||||
#if defined _WIN32
|
||||
#include <crtdbg.h>
|
||||
#pragma warning(disable:4996)
|
||||
#endif
|
||||
|
||||
@ -200,6 +201,8 @@ void setup_test_environment()
|
||||
{
|
||||
#if defined _WIN32
|
||||
_set_abort_behavior( 0, _WRITE_ABORT_MSG);
|
||||
_CrtSetReportMode( _CRT_ASSERT, _CRTDBG_MODE_FILE );
|
||||
_CrtSetReportFile( _CRT_ASSERT, _CRTDBG_FILE_STDERR );
|
||||
#endif
|
||||
}
|
||||
|
||||
|
Loading…
Reference in New Issue
Block a user