Functions | |
| void | sleep (UInt32 milliSeconds) |
| Suspend execution of the current thread until the given number of milliSeconds have elapsed. | |
| void | yield () |
| Voluntarily yield to the processor giving the next thread in the chain the opportunity to run. | |
| static void * | threadStarter (void *arg) |
| static void | initializeTheKey () |
| int | createThread (Thread_t &handle, ThreadFunction func, void *funcParm, UInt32 threadFlags) |
| Starts a thread running the given function. | |
| void | exitThread (Thread_t &handle, Int32 rval) |
| Exit thread method. | |
| UInt64 | thread_t_ToUInt64 (Thread_t thr) |
| Convert a Thread_t to an UInt64. | |
| void | destroyThread (Thread_t &handle) |
| Destroy any resources associated with a thread that was created with the createThread method. | |
| int | setThreadDetached (Thread_t &handle) |
| Set a thread that was previously in the joinable state to a detached state. | |
| int | joinThread (Thread_t &handle, Int32 &rval) |
| Join a thread that has been previously set to joinable. | |
| void | testCancel () |
| Test if this thread has been cancelled. | |
| void | saveThreadInTLS (void *pTheThread) |
| void | sendSignalToThread (Thread_t threadID, int signo) |
| void | cancel (Thread_t threadID) |
| bool | sameThreads (const volatile Thread_t &handle1, const volatile Thread_t &handle2) |
| Check two platform dependant thread types for equality. | |
| Thread_t | currentThread () |
| |
| void | memoryBarrier () |
| Deprecated because no code should need to use this, and if some does it should be rewritten to use the other thread primitives. | |
Variables | |
| default_stack_size | g_theDefaultStackSize |
| pthread_once_t | once_control = PTHREAD_ONCE_INIT |
| pthread_key_t | theKey |
It also contains other misellaneous functions which are useful for synchronization and threads. It is essentially an abstraction layer over a thread implementation.
| void BLOCXX_NAMESPACE::ThreadImpl::cancel | ( | Thread_t | threadID | ) |
Definition at line 388 of file ThreadImpl.cpp.
References BLOCXX_THROW.
Referenced by BLOCXX_NAMESPACE::Thread::cancel().
| int BLOCXX_NAMESPACE::ThreadImpl::createThread | ( | Thread_t & | handle, | |
| ThreadFunction | func, | |||
| void * | funcParm, | |||
| UInt32 | threadFlags | |||
| ) |
Starts a thread running the given function.
| handle | A platform specific thread handle | |
| func | The function that will run within the new thread. | |
| funcParm | The parameter to func | |
| threadFlags | The flags to use when creating the thread. Currently flags can contain the following: THREAD_JOINABLE - Thread will be created in the joinable state. |
Definition at line 249 of file ThreadImpl.cpp.
References BLOCXX_THREAD_FLG_JOINABLE, needsSetting, threadStarter(), and val.
Referenced by BLOCXX_NAMESPACE::Thread::start().
| Thread_t BLOCXX_NAMESPACE::ThreadImpl::currentThread | ( | ) | [inline] |
Definition at line 108 of file ThreadImpl.hpp.
Referenced by BLOCXX_NAMESPACE::RWLocker::getReadLock(), BLOCXX_NAMESPACE::RWLocker::getWriteLock(), and BLOCXX_NAMESPACE::RWLocker::releaseReadLock().
| void BLOCXX_NAMESPACE::ThreadImpl::destroyThread | ( | Thread_t & | handle | ) |
Destroy any resources associated with a thread that was created with the createThread method.
| handle | A platform specific thread handle |
Definition at line 311 of file ThreadImpl.cpp.
Referenced by BLOCXX_NAMESPACE::Thread::~Thread().
| void BLOCXX_NAMESPACE::ThreadImpl::exitThread | ( | Thread_t & | handle, | |
| Int32 | rval | |||
| ) |
Exit thread method.
This method is called everytime a thread exits. When the POSIX threads are being used, pthread_exit is called. This function does not return.
| handle | The thread handle of the calling thread. | |
| rval | The thread's return value. This can get picked up by joinThread. |
Definition at line 281 of file ThreadImpl.cpp.
Referenced by BLOCXX_NAMESPACE::Thread::threadRunner().
| static void BLOCXX_NAMESPACE::ThreadImpl::@219::initializeTheKey | ( | ) | [static] |
Definition at line 229 of file ThreadImpl.cpp.
References theKey.
Referenced by saveThreadInTLS(), and testCancel().
| int BLOCXX_NAMESPACE::ThreadImpl::joinThread | ( | Thread_t & | handle, | |
| Int32 & | rval | |||
| ) |
Join a thread that has been previously set to joinable.
It is Assumed that if the thread has already terminated, this method will still succeed and return immediately.
| handle | A handle to the thread to join with. | |
| rval | An out parameter of the thread's return code. |
Definition at line 332 of file ThreadImpl.cpp.
Referenced by BLOCXX_NAMESPACE::Thread::join().
| void BLOCXX_NAMESPACE::ThreadImpl::memoryBarrier | ( | ) | [inline] |
Deprecated because no code should need to use this, and if some does it should be rewritten to use the other thread primitives.
Definition at line 160 of file ThreadImpl.hpp.
| bool BLOCXX_NAMESPACE::ThreadImpl::sameThreads | ( | const volatile Thread_t & | handle1, | |
| const volatile Thread_t & | handle2 | |||
| ) | [inline] |
Check two platform dependant thread types for equality.
| handle1 | The 1st thread type for the comparison. | |
| handle2 | The 2nd thread type for the comparison. |
Definition at line 88 of file ThreadImpl.hpp.
Referenced by BLOCXX_NAMESPACE::RWLocker::getReadLock(), BLOCXX_NAMESPACE::RWLocker::getWriteLock(), BLOCXX_NAMESPACE::RWLocker::releaseReadLock(), and BLOCXX_NAMESPACE::sameId().
| void BLOCXX_NAMESPACE::ThreadImpl::saveThreadInTLS | ( | void * | pTheThread | ) |
Definition at line 368 of file ThreadImpl.cpp.
References BLOCXX_THROW, initializeTheKey(), once_control, and theKey.
Referenced by BLOCXX_NAMESPACE::Thread::threadRunner().
| void BLOCXX_NAMESPACE::ThreadImpl::sendSignalToThread | ( | Thread_t | threadID, | |
| int | signo | |||
| ) |
Definition at line 379 of file ThreadImpl.cpp.
References BLOCXX_THROW.
Referenced by BLOCXX_NAMESPACE::Thread::cooperativeCancel(), and BLOCXX_NAMESPACE::Thread::definitiveCancel().
| int BLOCXX_NAMESPACE::ThreadImpl::setThreadDetached | ( | Thread_t & | handle | ) |
Set a thread that was previously in the joinable state to a detached state.
This will allow the threads resources to be released upon termination without being joined. A thread that is in the detached state can no longer be joined.
| handle | The thread to set to the detached state. |
Definition at line 317 of file ThreadImpl.cpp.
| void BLOCXX_NAMESPACE::ThreadImpl::sleep | ( | UInt32 | milliSeconds | ) |
Suspend execution of the current thread until the given number of milliSeconds have elapsed.
| milliSeconds | The number of milliseconds to suspend execution for. |
Definition at line 84 of file ThreadImpl.cpp.
References BLOCXX_NAMESPACE::Select::select(), and testCancel().
Referenced by BLOCXX_NAMESPACE::milliSleep(), BLOCXX_NAMESPACE::secSleep(), BLOCXX_NAMESPACE::Thread::sleep(), and yield().
| void BLOCXX_NAMESPACE::ThreadImpl::testCancel | ( | ) |
Test if this thread has been cancelled.
If so, a ThreadCancelledException will be thrown. DO NOT catch this exception. ThreadCancelledException is not derived from anything. Do not write code like this: try { //... } catch (...) { // swallow all exceptions }
Instead do this: try { //... } catch (ThreadCancelledException&) { throw; } catch (std::exception& e) { // handle the exception } The only place ThreadCancelledException should be caught is in Thread::threadRunner(). main() shouldn't need to catch it, as the main thread of an application should never be cancelled. The main thread shouldn't need to ever call testCancel. Note that this method is staic, and it will check the the current running thread has been cacelled. Thus, you can't call it on an object that doesn't represent the current running thread and expect it to work.
Definition at line 347 of file ThreadImpl.cpp.
References initializeTheKey(), BLOCXX_NAMESPACE::Thread::m_cancelLock, BLOCXX_NAMESPACE::Thread::m_cancelRequested, once_control, and theKey.
Referenced by BLOCXX_NAMESPACE::ServerSocketImpl::accept(), BLOCXX_NAMESPACE::SocketBaseImpl::connect(), BLOCXX_NAMESPACE::noIntrWaitPid(), BLOCXX_NAMESPACE::Exec::safeSystem(), BLOCXX_NAMESPACE::Select::selectRWEpoll(), BLOCXX_NAMESPACE::Select::selectRWPoll(), BLOCXX_NAMESPACE::Select::selectRWSelect(), sleep(), BLOCXX_NAMESPACE::Thread::testCancel(), and yield().
| UInt64 BLOCXX_NAMESPACE::ThreadImpl::thread_t_ToUInt64 | ( | Thread_t | thr | ) |
Convert a Thread_t to an UInt64.
This hides platform dependencies like that fact that on some platforms (e.g linux) Thread_t is integral type, and can therefor be static_cast<>ed to unsigned long, but on other platforms, like FreeBSD, Thread_t is void*, or something else, and reinterpret_cast<> (hopefully that works ...) must be used.
Definition at line 302 of file ThreadImpl.cpp.
References BLOCXX_THREAD_CONVERTER.
| static void* BLOCXX_NAMESPACE::ThreadImpl::@219::threadStarter | ( | void * | arg | ) | [static] |
Definition at line 154 of file ThreadImpl.cpp.
References BLOCXX_ASSERT.
Referenced by createThread().
| void BLOCXX_NAMESPACE::ThreadImpl::yield | ( | ) |
Voluntarily yield to the processor giving the next thread in the chain the opportunity to run.
Definition at line 133 of file ThreadImpl.cpp.
References sleep(), and testCancel().
Referenced by BLOCXX_NAMESPACE::Thread::yield().
default_stack_size BLOCXX_NAMESPACE::ThreadImpl::g_theDefaultStackSize [static] |
Definition at line 223 of file ThreadImpl.cpp.
pthread_once_t BLOCXX_NAMESPACE::ThreadImpl::once_control = PTHREAD_ONCE_INIT [static] |
pthread_key_t BLOCXX_NAMESPACE::ThreadImpl::theKey [static] |
Definition at line 226 of file ThreadImpl.cpp.
Referenced by initializeTheKey(), saveThreadInTLS(), and testCancel().
1.5.3