summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
-rw-r--r--src/thread.cpp54
-rw-r--r--src/thread.hpp10
-rw-r--r--tests/test_shutdown_stress.cpp19
3 files changed, 46 insertions, 37 deletions
diff --git a/src/thread.cpp b/src/thread.cpp
index 2edd85b..874190e 100644
--- a/src/thread.cpp
+++ b/src/thread.cpp
@@ -23,6 +23,16 @@
#ifdef ZMQ_HAVE_WINDOWS
+extern "C"
+{
+ static unsigned int __stdcall thread_routine (void *arg_)
+ {
+ thread_t *self = (zmq::thread_t*) arg_;
+ self->tfn (self->arg);
+ return 0;
+ }
+}
+
void zmq::thread_t::start (thread_fn *tfn_, void *arg_)
{
tfn = tfn_;
@@ -38,17 +48,30 @@ void zmq::thread_t::stop ()
win_assert (rc != WAIT_FAILED);
}
-unsigned int __stdcall zmq::thread_t::thread_routine (void *arg_)
-{
- thread_t *self = (thread_t*) arg_;
- self->tfn (self->arg);
- return 0;
-}
-
#else
#include <signal.h>
+extern "C"
+{
+ static void *thread_routine (void *arg_)
+ {
+ #if !defined ZMQ_HAVE_OPENVMS
+ // Following code will guarantee more predictable latecnies as it'll
+ // disallow any signal handling in the I/O thread.
+ sigset_t signal_set;
+ int rc = sigfillset (&signal_set);
+ errno_assert (rc == 0);
+ rc = pthread_sigmask (SIG_BLOCK, &signal_set, NULL);
+ errno_assert (rc == 0);
+ #endif
+
+ zmq::thread_t *self = (zmq::thread_t*) arg_;
+ self->tfn (self->arg);
+ return NULL;
+ }
+}
+
void zmq::thread_t::start (thread_fn *tfn_, void *arg_)
{
tfn = tfn_;
@@ -63,23 +86,6 @@ void zmq::thread_t::stop ()
errno_assert (rc == 0);
}
-void *zmq::thread_t::thread_routine (void *arg_)
-{
-#if !defined ZMQ_HAVE_OPENVMS
- // Following code will guarantee more predictable latecnies as it'll
- // disallow any signal handling in the I/O thread.
- sigset_t signal_set;
- int rc = sigfillset (&signal_set);
- errno_assert (rc == 0);
- rc = pthread_sigmask (SIG_BLOCK, &signal_set, NULL);
- errno_assert (rc == 0);
-#endif
-
- thread_t *self = (thread_t*) arg_;
- self->tfn (self->arg);
- return NULL;
-}
-
#endif
diff --git a/src/thread.hpp b/src/thread.hpp
index 519a34a..46745a5 100644
--- a/src/thread.hpp
+++ b/src/thread.hpp
@@ -54,20 +54,20 @@ namespace zmq
// Waits for thread termination.
void stop ();
+
+ // These are internal members. They should be private, however then
+ // they would not be accessible from the main C routine of the thread.
+ thread_fn *tfn;
+ void *arg;
private:
#ifdef ZMQ_HAVE_WINDOWS
- static unsigned int __stdcall thread_routine (void *arg_);
HANDLE descriptor;
#else
- static void *thread_routine (void *arg_);
pthread_t descriptor;
#endif
- thread_fn *tfn;
- void *arg;
-
thread_t (const thread_t&);
void operator = (const thread_t&);
};
diff --git a/tests/test_shutdown_stress.cpp b/tests/test_shutdown_stress.cpp
index a8079d4..fed67b7 100644
--- a/tests/test_shutdown_stress.cpp
+++ b/tests/test_shutdown_stress.cpp
@@ -24,18 +24,21 @@
#define THREAD_COUNT 100
-void *worker (void *s)
+extern "C"
{
- int rc;
+ static void *worker (void *s)
+ {
+ int rc;
- rc = zmq_connect (s, "tcp://127.0.0.1:5555");
- assert (rc == 0);
+ rc = zmq_connect (s, "tcp://127.0.0.1:5555");
+ assert (rc == 0);
- // Start closing the socket while the connecting process is underway.
- rc = zmq_close (s);
- assert (rc == 0);
+ // Start closing the socket while the connecting process is underway.
+ rc = zmq_close (s);
+ assert (rc == 0);
- return NULL;
+ return NULL;
+ }
}
int main (int argc, char *argv [])