diff options
| author | Andrew Stitcher <astitcher@apache.org> | 2010-04-21 22:07:04 +0000 |
|---|---|---|
| committer | Andrew Stitcher <astitcher@apache.org> | 2010-04-21 22:07:04 +0000 |
| commit | 49058d80637096b65b198d4dce7fb98a1151d2b0 (patch) | |
| tree | 2d2c6d77130f2337015c66b62df2ec125d211320 /cpp/src/qpid/sys/posix | |
| parent | 26d81efa13c8878f4584a721a3f0ea72ce27775f (diff) | |
| download | qpid-python-49058d80637096b65b198d4dce7fb98a1151d2b0.tar.gz | |
QPID-2527: Remove Thread::id member as its uses are better implemented by comparison
operators.
git-svn-id: https://svn.apache.org/repos/asf/qpid/trunk/qpid@936537 13f79535-47bb-0310-9956-ffa450edef68
Diffstat (limited to 'cpp/src/qpid/sys/posix')
| -rw-r--r-- | cpp/src/qpid/sys/posix/Thread.cpp | 26 |
1 files changed, 19 insertions, 7 deletions
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() { |
