diff options
author | Mike Buland <eichlan@xagasoft.com> | 2012-04-06 18:45:08 +0000 |
---|---|---|
committer | Mike Buland <eichlan@xagasoft.com> | 2012-04-06 18:45:08 +0000 |
commit | b7745f00eacb2ca5b9c56331006f4f37d2566fdc (patch) | |
tree | 62530f6a0631d13e1289b19800612548dca8fb7b | |
parent | 9fa0f9cea3b92b3d44257a612731456fea629c68 (diff) | |
download | libbu++-b7745f00eacb2ca5b9c56331006f4f37d2566fdc.tar.gz libbu++-b7745f00eacb2ca5b9c56331006f4f37d2566fdc.tar.bz2 libbu++-b7745f00eacb2ca5b9c56331006f4f37d2566fdc.tar.xz libbu++-b7745f00eacb2ca5b9c56331006f4f37d2566fdc.zip |
Supports ThreadIds now, you can also get the thread id of any thread, and
compare ThreadId objects.
Diffstat (limited to '')
-rw-r--r-- | default.bld | 3 | ||||
-rw-r--r-- | src/stable/thread.cpp | 24 | ||||
-rw-r--r-- | src/stable/thread.h | 19 |
3 files changed, 43 insertions, 3 deletions
diff --git a/default.bld b/default.bld index 831959e..c6721b2 100644 --- a/default.bld +++ b/default.bld | |||
@@ -210,8 +210,7 @@ target ["tests/lzma"] | |||
210 | LDFLAGS += "-llzma"; | 210 | LDFLAGS += "-llzma"; |
211 | } | 211 | } |
212 | 212 | ||
213 | target ["tests/itoserver", "tests/socketblock", "tests/itoheap", | 213 | target ["tests/threadid"] |
214 | "tests/itoqueue1", "tests/itoqueue2", "tests/conduit"] | ||
215 | { | 214 | { |
216 | LDFLAGS += "-lpthread"; | 215 | LDFLAGS += "-lpthread"; |
217 | } | 216 | } |
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 @@ | |||
9 | 9 | ||
10 | #include "bu/config.h" | 10 | #include "bu/config.h" |
11 | 11 | ||
12 | Bu::ThreadId::ThreadId( pthread_t tId ) : | ||
13 | tId( tId ) | ||
14 | { | ||
15 | } | ||
16 | |||
17 | Bu::ThreadId::ThreadId() | ||
18 | { | ||
19 | } | ||
20 | |||
21 | bool Bu::ThreadId::operator==( const Bu::ThreadId &rhs ) | ||
22 | { | ||
23 | return pthread_equal( tId, rhs.tId ); | ||
24 | } | ||
25 | |||
26 | bool Bu::ThreadId::operator!=( const ThreadId &rhs ) | ||
27 | { | ||
28 | return !pthread_equal( tId, rhs.tId ); | ||
29 | } | ||
30 | |||
12 | Bu::Thread::Thread() | 31 | Bu::Thread::Thread() |
13 | { | 32 | { |
14 | } | 33 | } |
@@ -17,6 +36,11 @@ Bu::Thread::~Thread() | |||
17 | { | 36 | { |
18 | } | 37 | } |
19 | 38 | ||
39 | Bu::ThreadId Bu::Thread::currentThread() | ||
40 | { | ||
41 | return ThreadId( pthread_self() ); | ||
42 | } | ||
43 | |||
20 | bool Bu::Thread::start() | 44 | bool Bu::Thread::start() |
21 | { | 45 | { |
22 | nHandle = pthread_create( &ptHandle, NULL, threadRunner, this ); | 46 | 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 @@ | |||
12 | 12 | ||
13 | namespace Bu | 13 | namespace Bu |
14 | { | 14 | { |
15 | class ThreadId | ||
16 | { | ||
17 | friend class Thread; | ||
18 | private: | ||
19 | ThreadId( pthread_t tId ); | ||
20 | |||
21 | public: | ||
22 | ThreadId(); | ||
23 | |||
24 | bool operator==( const ThreadId &rhs ); | ||
25 | bool operator!=( const ThreadId &rhs ); | ||
26 | |||
27 | private: | ||
28 | pthread_t tId; | ||
29 | }; | ||
30 | |||
15 | /** | 31 | /** |
16 | * Simple thread class. This wraps the basic pthread (posix threads) | 32 | * Simple thread class. This wraps the basic pthread (posix threads) |
17 | * system in an object oriented sort of way. It allows you to create a | 33 | * system in an object oriented sort of way. It allows you to create a |
@@ -32,6 +48,8 @@ namespace Bu | |||
32 | */ | 48 | */ |
33 | virtual ~Thread(); | 49 | virtual ~Thread(); |
34 | 50 | ||
51 | static ThreadId currentThread(); | ||
52 | |||
35 | /** | 53 | /** |
36 | * Begin thread execution. This will call the overridden run function, | 54 | * Begin thread execution. This will call the overridden run function, |
37 | * which will simply execute in it's own thread until the function | 55 | * which will simply execute in it's own thread until the function |
@@ -100,7 +118,6 @@ namespace Bu | |||
100 | static void *threadRunner( void *pThread ); | 118 | static void *threadRunner( void *pThread ); |
101 | 119 | ||
102 | void yield(); | 120 | void yield(); |
103 | |||
104 | }; | 121 | }; |
105 | } | 122 | } |
106 | 123 | ||