diff options
-rw-r--r-- | src/stable/thread.cpp | 7 | ||||
-rw-r--r-- | src/stable/thread.h | 9 |
2 files changed, 12 insertions, 4 deletions
diff --git a/src/stable/thread.cpp b/src/stable/thread.cpp index 0d0b768..9cf223e 100644 --- a/src/stable/thread.cpp +++ b/src/stable/thread.cpp | |||
@@ -9,6 +9,8 @@ | |||
9 | 9 | ||
10 | #include "bu/config.h" | 10 | #include "bu/config.h" |
11 | 11 | ||
12 | namespace Bu { subExceptionDef( ThreadException ); } | ||
13 | |||
12 | Bu::ThreadId::ThreadId( pthread_t tId ) : | 14 | Bu::ThreadId::ThreadId( pthread_t tId ) : |
13 | tId( tId ) | 15 | tId( tId ) |
14 | { | 16 | { |
@@ -43,7 +45,10 @@ Bu::ThreadId Bu::Thread::currentThread() | |||
43 | 45 | ||
44 | bool Bu::Thread::start() | 46 | bool Bu::Thread::start() |
45 | { | 47 | { |
46 | nHandle = pthread_create( &ptHandle, NULL, threadRunner, this ); | 48 | if( pthread_create( &ptHandle, NULL, threadRunner, this ) ) |
49 | { | ||
50 | throw Bu::ThreadException("Could not start thread."); | ||
51 | } | ||
47 | 52 | ||
48 | return true; | 53 | return true; |
49 | } | 54 | } |
diff --git a/src/stable/thread.h b/src/stable/thread.h index f4b961f..0a0d8bb 100644 --- a/src/stable/thread.h +++ b/src/stable/thread.h | |||
@@ -10,8 +10,11 @@ | |||
10 | 10 | ||
11 | #include <pthread.h> | 11 | #include <pthread.h> |
12 | 12 | ||
13 | #include "bu/exceptionbase.h" | ||
14 | |||
13 | namespace Bu | 15 | namespace Bu |
14 | { | 16 | { |
17 | subExceptionDecl( ThreadException ); | ||
15 | class ThreadId | 18 | class ThreadId |
16 | { | 19 | { |
17 | friend class Thread; | 20 | friend class Thread; |
@@ -49,6 +52,7 @@ namespace Bu | |||
49 | virtual ~Thread(); | 52 | virtual ~Thread(); |
50 | 53 | ||
51 | static ThreadId currentThread(); | 54 | static ThreadId currentThread(); |
55 | ThreadId getId() { return ThreadId( ptHandle ); } | ||
52 | 56 | ||
53 | /** | 57 | /** |
54 | * Begin thread execution. This will call the overridden run function, | 58 | * Begin thread execution. This will call the overridden run function, |
@@ -93,12 +97,11 @@ namespace Bu | |||
93 | 97 | ||
94 | private: | 98 | private: |
95 | pthread_t ptHandle; /**< Internal handle to the posix thread. */ | 99 | pthread_t ptHandle; /**< Internal handle to the posix thread. */ |
96 | int nHandle; /**< Numeric handle to the posix thread. */ | ||
97 | 100 | ||
98 | protected: | 101 | protected: |
99 | /** | 102 | /** |
100 | * The workhorse of the Thread class. This is the function that will run | 103 | * The workhorse of the Thread class. This is the function that will |
101 | * in the thread, when this function exits the thread dies and is | 104 | * run in the thread, when this function exits the thread dies and is |
102 | * cleaned up by the system. Make sure to read up on ThreadMutex, | 105 | * cleaned up by the system. Make sure to read up on ThreadMutex, |
103 | * ThreadCondition, and cancel to see how to control and protect | 106 | * ThreadCondition, and cancel to see how to control and protect |
104 | * everything you do in a safe way within this function. | 107 | * everything you do in a safe way within this function. |