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

bug in identifying current thread fixed

parent 6996ef6f
......@@ -44,7 +44,7 @@
zmq::app_thread_t::app_thread_t (dispatcher_t *dispatcher_, int thread_slot_) :
object_t (dispatcher_, thread_slot_),
tid (0),
associated (false),
last_processing_time (0)
{
}
......@@ -63,7 +63,8 @@ zmq::i_signaler *zmq::app_thread_t::get_signaler ()
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 ()
......@@ -73,7 +74,8 @@ bool zmq::app_thread_t::make_current ()
if (!sockets.empty ())
return false;
tid = getpid ();
associated = true;
tid = thread_t::id ();
return true;
}
......
......@@ -25,6 +25,7 @@
#include "stdint.hpp"
#include "object.hpp"
#include "ypollset.hpp"
#include "thread.hpp"
namespace zmq
{
......@@ -69,10 +70,12 @@ namespace zmq
typedef std::vector <class socket_base_t*> sockets_t;
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.
// TODO: Virtualise pid_t!
// TODO: Check whether getpid returns unique ID for each thread.
int tid;
thread_t::id_t tid;
// App thread's signaler object.
ypollset_t pollset;
......
......@@ -38,6 +38,16 @@ void zmq::thread_t::stop ()
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_)
{
thread_t *self = (thread_t*) arg_;
......@@ -63,6 +73,16 @@ void zmq::thread_t::stop ()
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_)
{
#if !defined ZMQ_HAVE_OPENVMS
......
......@@ -55,6 +55,15 @@ namespace zmq
// Waits for thread termination.
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:
#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