Commit 3666a490 authored by Martin Sustrik's avatar Martin Sustrik

bug in identifying current thread fixed

parent 6996ef6f
...@@ -44,7 +44,7 @@ ...@@ -44,7 +44,7 @@
zmq::app_thread_t::app_thread_t (dispatcher_t *dispatcher_, int thread_slot_) : zmq::app_thread_t::app_thread_t (dispatcher_t *dispatcher_, int thread_slot_) :
object_t (dispatcher_, thread_slot_), object_t (dispatcher_, thread_slot_),
tid (0), associated (false),
last_processing_time (0) last_processing_time (0)
{ {
} }
...@@ -63,7 +63,8 @@ zmq::i_signaler *zmq::app_thread_t::get_signaler () ...@@ -63,7 +63,8 @@ zmq::i_signaler *zmq::app_thread_t::get_signaler ()
bool zmq::app_thread_t::is_current () bool zmq::app_thread_t::is_current ()
{ {
return !sockets.empty () && tid == getpid (); return !sockets.empty () && associated &&
thread_t::equal (tid, thread_t::id ());
} }
bool zmq::app_thread_t::make_current () bool zmq::app_thread_t::make_current ()
...@@ -73,7 +74,8 @@ bool zmq::app_thread_t::make_current () ...@@ -73,7 +74,8 @@ bool zmq::app_thread_t::make_current ()
if (!sockets.empty ()) if (!sockets.empty ())
return false; return false;
tid = getpid (); associated = true;
tid = thread_t::id ();
return true; return true;
} }
......
...@@ -25,6 +25,7 @@ ...@@ -25,6 +25,7 @@
#include "stdint.hpp" #include "stdint.hpp"
#include "object.hpp" #include "object.hpp"
#include "ypollset.hpp" #include "ypollset.hpp"
#include "thread.hpp"
namespace zmq namespace zmq
{ {
...@@ -69,10 +70,12 @@ namespace zmq ...@@ -69,10 +70,12 @@ namespace zmq
typedef std::vector <class socket_base_t*> sockets_t; typedef std::vector <class socket_base_t*> sockets_t;
sockets_t sockets; sockets_t sockets;
// If false, app_thread_t object is not associated with any OS thread.
// In such case, 'tid' member contains a bogus value.
bool associated;
// Thread ID associated with this slot. // Thread ID associated with this slot.
// TODO: Virtualise pid_t! thread_t::id_t tid;
// TODO: Check whether getpid returns unique ID for each thread.
int tid;
// App thread's signaler object. // App thread's signaler object.
ypollset_t pollset; ypollset_t pollset;
......
...@@ -38,6 +38,16 @@ void zmq::thread_t::stop () ...@@ -38,6 +38,16 @@ void zmq::thread_t::stop ()
win_assert (rc != WAIT_FAILED); win_assert (rc != WAIT_FAILED);
} }
zmq::thread_t::id_t zmq::thread_t::id ()
{
return GetCurrentThreadId ();
}
bool zmq::thread_t::equal (id_t id1_, id_t id2_)
{
return id1_ == id2_;
}
unsigned int __stdcall zmq::thread_t::thread_routine (void *arg_) unsigned int __stdcall zmq::thread_t::thread_routine (void *arg_)
{ {
thread_t *self = (thread_t*) arg_; thread_t *self = (thread_t*) arg_;
...@@ -63,6 +73,16 @@ void zmq::thread_t::stop () ...@@ -63,6 +73,16 @@ void zmq::thread_t::stop ()
errno_assert (rc == 0); errno_assert (rc == 0);
} }
zmq::thread_t::id_t zmq::thread_t::id ()
{
return pthread_self ();
}
bool zmq::thread_t::equal (id_t id1_, id_t id2_)
{
return pthread_equal (id1_, id2_) != 0;
}
void *zmq::thread_t::thread_routine (void *arg_) void *zmq::thread_t::thread_routine (void *arg_)
{ {
#if !defined ZMQ_HAVE_OPENVMS #if !defined ZMQ_HAVE_OPENVMS
......
...@@ -55,6 +55,15 @@ namespace zmq ...@@ -55,6 +55,15 @@ namespace zmq
// Waits for thread termination. // Waits for thread termination.
void stop (); void stop ();
#ifdef ZMQ_HAVE_WINDOWS
typedef DWORD id_t;
#else
typedef pthread_t id_t;
#endif
static id_t id ();
static bool equal (id_t id1_, id_t id2_);
private: private:
#ifdef ZMQ_HAVE_WINDOWS #ifdef ZMQ_HAVE_WINDOWS
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment