From b7745f00eacb2ca5b9c56331006f4f37d2566fdc Mon Sep 17 00:00:00 2001 From: Mike Buland Date: Fri, 6 Apr 2012 18:45:08 +0000 Subject: Supports ThreadIds now, you can also get the thread id of any thread, and compare ThreadId objects. --- src/stable/thread.cpp | 24 ++++++++++++++++++++++++ src/stable/thread.h | 19 ++++++++++++++++++- 2 files changed, 42 insertions(+), 1 deletion(-) (limited to 'src') diff --git a/src/stable/thread.cpp b/src/stable/thread.cpp index e4563a2..0d0b768 100644 --- a/src/stable/thread.cpp +++ b/src/stable/thread.cpp @@ -9,6 +9,25 @@ #include "bu/config.h" +Bu::ThreadId::ThreadId( pthread_t tId ) : + tId( tId ) +{ +} + +Bu::ThreadId::ThreadId() +{ +} + +bool Bu::ThreadId::operator==( const Bu::ThreadId &rhs ) +{ + return pthread_equal( tId, rhs.tId ); +} + +bool Bu::ThreadId::operator!=( const ThreadId &rhs ) +{ + return !pthread_equal( tId, rhs.tId ); +} + Bu::Thread::Thread() { } @@ -17,6 +36,11 @@ Bu::Thread::~Thread() { } +Bu::ThreadId Bu::Thread::currentThread() +{ + return ThreadId( pthread_self() ); +} + bool Bu::Thread::start() { nHandle = pthread_create( &ptHandle, NULL, threadRunner, this ); diff --git a/src/stable/thread.h b/src/stable/thread.h index 70e6f5f..f4b961f 100644 --- a/src/stable/thread.h +++ b/src/stable/thread.h @@ -12,6 +12,22 @@ namespace Bu { + class ThreadId + { + friend class Thread; + private: + ThreadId( pthread_t tId ); + + public: + ThreadId(); + + bool operator==( const ThreadId &rhs ); + bool operator!=( const ThreadId &rhs ); + + private: + pthread_t tId; + }; + /** * Simple thread class. This wraps the basic pthread (posix threads) * system in an object oriented sort of way. It allows you to create a @@ -32,6 +48,8 @@ namespace Bu */ virtual ~Thread(); + static ThreadId currentThread(); + /** * Begin thread execution. This will call the overridden run function, * which will simply execute in it's own thread until the function @@ -100,7 +118,6 @@ namespace Bu static void *threadRunner( void *pThread ); void yield(); - }; } -- cgit v1.2.3