diff options
Diffstat (limited to 'cpp/src/qpid/sys')
| -rw-r--r-- | cpp/src/qpid/sys/PollableQueue.h | 6 | ||||
| -rw-r--r-- | cpp/src/qpid/sys/posix/Thread.cpp | 26 | ||||
| -rwxr-xr-x | cpp/src/qpid/sys/windows/Thread.cpp | 16 |
3 files changed, 36 insertions, 12 deletions
diff --git a/cpp/src/qpid/sys/PollableQueue.h b/cpp/src/qpid/sys/PollableQueue.h index cb8c126fe6..81c2301c1e 100644 --- a/cpp/src/qpid/sys/PollableQueue.h +++ b/cpp/src/qpid/sys/PollableQueue.h @@ -132,7 +132,7 @@ template <class T> void PollableQueue<T>::push(const T& t) { template <class T> void PollableQueue<T>::dispatch(PollableCondition& cond) { ScopedLock l(lock); - assert(dispatcher.id() == 0); + assert(!dispatcher); dispatcher = Thread::current(); process(); dispatcher = Thread(); @@ -167,8 +167,8 @@ template <class T> void PollableQueue<T>::stop() { condition.clear(); stopped = true; // Avoid deadlock if stop is called from the dispatch thread - if (dispatcher.id() != Thread::current().id()) - while (dispatcher.id()) lock.wait(); + if (dispatcher && dispatcher != Thread::current()) + while (dispatcher) lock.wait(); } }} // namespace qpid::sys diff --git a/cpp/src/qpid/sys/posix/Thread.cpp b/cpp/src/qpid/sys/posix/Thread.cpp index a784e63195..b466733260 100644 --- a/cpp/src/qpid/sys/posix/Thread.cpp +++ b/cpp/src/qpid/sys/posix/Thread.cpp @@ -39,11 +39,11 @@ void* runRunnable(void* p) struct ThreadPrivate { pthread_t thread; - + ThreadPrivate(Runnable* runnable) { QPID_POSIX_ASSERT_THROW_IF(::pthread_create(&thread, NULL, runRunnable, runnable)); } - + ThreadPrivate() : thread(::pthread_self()) {} }; @@ -53,17 +53,29 @@ Thread::Thread(Runnable* runnable) : impl(new ThreadPrivate(runnable)) {} Thread::Thread(Runnable& runnable) : impl(new ThreadPrivate(&runnable)) {} +Thread::operator bool() { + return impl; +} + +bool Thread::operator==(const Thread& t) const { + return ::pthread_equal(impl->thread, t.impl->thread) != 0; +} + +bool Thread::operator!=(const Thread& t) const { + return !(*this==t); +} + void Thread::join(){ if (impl) { QPID_POSIX_ASSERT_THROW_IF(::pthread_join(impl->thread, 0)); } } -unsigned long Thread::id() { - if (impl) - return impl->thread; - else - return 0; +unsigned long Thread::logId() { + // This does need to be the C cast operator as + // pthread_t could be either a pointer or an integer + // and so we can't know static_cast<> or reinterpret_cast<> + return (unsigned long) ::pthread_self(); } Thread Thread::current() { diff --git a/cpp/src/qpid/sys/windows/Thread.cpp b/cpp/src/qpid/sys/windows/Thread.cpp index fed82e4d54..583a9613a3 100755 --- a/cpp/src/qpid/sys/windows/Thread.cpp +++ b/cpp/src/qpid/sys/windows/Thread.cpp @@ -65,6 +65,18 @@ Thread::Thread(Runnable* runnable) : impl(new ThreadPrivate(runnable)) {} Thread::Thread(Runnable& runnable) : impl(new ThreadPrivate(&runnable)) {} +Thread::operator bool() { + return impl; +} + +bool Thread::operator==(const Thread& t) const { + return impl->threadId == t.impl->threadId; +} + +bool Thread::operator!=(const Thread& t) const { + return !(*this==t); +} + void Thread::join() { if (impl) { DWORD status = WaitForSingleObject (impl->threadHandle, INFINITE); @@ -74,8 +86,8 @@ void Thread::join() { } } -unsigned long Thread::id() { - return impl ? impl->threadId : 0; +unsigned long Thread::logId() { + return GetCurrentThreadId(); } /* static */ |
