BLOCXX_NAMESPACE::ThreadImpl Namespace Reference

The ThreadImpl namespace represents the functionality needed by the BloCxx Thread class (Thread). More...


Functions

void sleep (UInt32 milliSeconds)
 Suspend execution of the current thread until the given number of milliSeconds have elapsed.
void sleep (const Timeout &timeout)
 Suspend execution of the current thread until the given number of seconds 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 SIGUSR1Handler (int sig)
static void doOneTimeThreadInitialization ()
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 ()

Variables

default_stack_size g_theDefaultStackSize
pthread_once_t once_control = PTHREAD_ONCE_INIT
pthread_key_t theKey


Detailed Description

The ThreadImpl namespace represents the functionality needed by the BloCxx Thread class (Thread).

It also contains other misellaneous functions which are useful for synchronization and threads. It is essentially an abstraction layer over a thread implementation.


Function Documentation

void BLOCXX_NAMESPACE::ThreadImpl::cancel ( Thread_t  threadID  ) 

Definition at line 488 of file ThreadImpl.cpp.

References BLOCXX_THROW.

Referenced by BLOCXX_NAMESPACE::Thread::cancel_internal().

int BLOCXX_NAMESPACE::ThreadImpl::createThread ( Thread_t &  handle,
ThreadFunction  func,
void *  funcParm,
UInt32  threadFlags 
)

Starts a thread running the given function.

Parameters:
handle A platform specific thread handle
func The function that will run within the new thread.
funcParm The parameter to func
flags The flags to use when creating the thread. Currently flags can contain the following: THREAD_JOINABLE - Thread will be created in the joinable state.
Returns:
0 on success. Otherwise -1 or a system error number (e.g. errno)

Definition at line 295 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]

void BLOCXX_NAMESPACE::ThreadImpl::destroyThread ( Thread_t &  handle  ) 

Destroy any resources associated with a thread that was created with the createThread method.

Parameters:
handle A platform specific thread handle

Definition at line 398 of file ThreadImpl.cpp.

Referenced by BLOCXX_NAMESPACE::Thread::~Thread().

static void BLOCXX_NAMESPACE::ThreadImpl::@281::doOneTimeThreadInitialization (  )  [static]

Definition at line 271 of file ThreadImpl.cpp.

References SIGUSR1Handler().

Referenced by saveThreadInTLS(), and testCancel().

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.

Parameters:
handle The thread handle of the calling thread.
rval The thread's return value. This can get picked up by joinThread.

Definition at line 360 of file ThreadImpl.cpp.

Referenced by BLOCXX_NAMESPACE::Thread::threadRunner().

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.

Parameters:
handle A handle to the thread to join with.
rval An out parameter of the thread's return code.
Returns:
0 on success. Otherwise -1

Definition at line 423 of file ThreadImpl.cpp.

Referenced by BLOCXX_NAMESPACE::Thread::join().

bool BLOCXX_NAMESPACE::ThreadImpl::sameThreads ( const volatile Thread_t &  handle1,
const volatile Thread_t &  handle2 
) [inline]

Check two platform dependant thread types for equality.

Parameters:
handle1 The 1st thread type for the comparison.
handle2 The 2nd thread type for the comparison.
Returns:
true if the thread types are equal. Otherwise false

Definition at line 97 of file ThreadImpl.hpp.

Referenced by BLOCXX_NAMESPACE::RWLocker::ThreadComparer::operator()(), BLOCXX_NAMESPACE::sameId(), and BLOCXX_NAMESPACE::WaitpidThreadFix::shouldUseWaitpidThreadFix().

void BLOCXX_NAMESPACE::ThreadImpl::saveThreadInTLS ( void *  pTheThread  ) 

void BLOCXX_NAMESPACE::ThreadImpl::sendSignalToThread ( Thread_t  threadID,
int  signo 
)

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.

Parameters:
handle The thread to set to the detached state.
Returns:
0 on success. Otherwise -1

Definition at line 404 of file ThreadImpl.cpp.

static void BLOCXX_NAMESPACE::ThreadImpl::@281::SIGUSR1Handler ( int  sig  )  [static]

Definition at line 264 of file ThreadImpl.cpp.

Referenced by doOneTimeThreadInitialization().

void BLOCXX_NAMESPACE::ThreadImpl::sleep ( const Timeout &  timeout  ) 

Suspend execution of the current thread until the given number of seconds have elapsed.

Parameters:
seconds The number of seconds to suspend execution for.

Definition at line 95 of file ThreadImpl.cpp.

References BLOCXX_NAMESPACE::TimeoutTimer::asAbsoluteTimeout(), BLOCXX_NAMESPACE::TimeoutTimer::expired(), BLOCXX_NAMESPACE::TimeoutTimer::loop(), and BLOCXX_NAMESPACE::Condition::timedWait().

Referenced by BLOCXX_NAMESPACE::Thread::sleep(), BLOCXX_NAMESPACE::Process::terminatesWithin(), and yield().

void BLOCXX_NAMESPACE::ThreadImpl::sleep ( UInt32  milliSeconds  ) 

Suspend execution of the current thread until the given number of milliSeconds have elapsed.

Parameters:
milliSeconds The number of milliseconds to suspend execution for.

Definition at line 89 of file ThreadImpl.cpp.

References BLOCXX_NAMESPACE::Timeout::relative().

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 438 of file ThreadImpl.cpp.

References BLOCXX_NAMESPACE::AtomicGet(), doOneTimeThreadInitialization(), BLOCXX_NAMESPACE::Thread::m_cancelRequested, once_control, and theKey.

Referenced by BLOCXX_NAMESPACE::ServerSocketImpl::accept(), BLOCXX_NAMESPACE::MutexImpl::acquireMutex(), BLOCXX_NAMESPACE::SocketBaseImpl::connect(), BLOCXX_NAMESPACE::Condition::doTimedWait(), BLOCXX_NAMESPACE::Condition::doWait(), BLOCXX_NAMESPACE::Select::selectRWEpoll(), BLOCXX_NAMESPACE::Select::selectRWPoll(), BLOCXX_NAMESPACE::Select::selectRWSelect(), BLOCXX_NAMESPACE::Thread::testCancel(), BLOCXX_NAMESPACE::upread(), BLOCXX_NAMESPACE::upwrite(), 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 385 of file ThreadImpl.cpp.

References BLOCXX_THREAD_CONVERTER.

Referenced by BLOCXX_NAMESPACE::id_function().

static void* BLOCXX_NAMESPACE::ThreadImpl::@281::threadStarter ( void *  arg  )  [static]

Definition at line 135 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 114 of file ThreadImpl.cpp.

References sleep(), and testCancel().

Referenced by BLOCXX_NAMESPACE::Thread::yield().


Variable Documentation

Definition at line 250 of file ThreadImpl.cpp.

pthread_once_t BLOCXX_NAMESPACE::ThreadImpl::once_control = PTHREAD_ONCE_INIT [static]

Definition at line 252 of file ThreadImpl.cpp.

Referenced by saveThreadInTLS(), and testCancel().

pthread_key_t BLOCXX_NAMESPACE::ThreadImpl::theKey [static]

Definition at line 253 of file ThreadImpl.cpp.

Referenced by saveThreadInTLS(), and testCancel().


Generated on Wed Feb 25 19:05:20 2009 for blocxx by  doxygen 1.5.6