OW_NAMESPACE::ThreadImpl Namespace Reference

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


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


Detailed Description

The ThreadImpl namespace represents the functionality needed by the OpenWbem 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 OW_NAMESPACE::ThreadImpl::cancel Thread_t  threadID  ) 
 

Definition at line 386 of file OW_ThreadImpl.cpp.

References OW_THROW.

Referenced by OW_NAMESPACE::Thread::cancel().

int OW_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

Definition at line 247 of file OW_ThreadImpl.cpp.

References needsSetting, OW_THREAD_FLG_JOINABLE, threadStarter(), and val.

Referenced by OW_NAMESPACE::Thread::start().

Thread_t OW_NAMESPACE::ThreadImpl::currentThread  )  [inline]
 

Returns:
The thread handle for the current running thread.

Definition at line 106 of file OW_ThreadImpl.hpp.

Referenced by OW_NAMESPACE::RWLocker::getReadLock(), OW_NAMESPACE::RWLocker::getWriteLock(), and OW_NAMESPACE::RWLocker::releaseReadLock().

void OW_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 309 of file OW_ThreadImpl.cpp.

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

void OW_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 279 of file OW_ThreadImpl.cpp.

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

static void OW_NAMESPACE::ThreadImpl::@0::initializeTheKey  )  [static]
 

Definition at line 227 of file OW_ThreadImpl.cpp.

References theKey.

Referenced by saveThreadInTLS(), CMPI_ThreadContext::setContext(), and testCancel().

int OW_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 330 of file OW_ThreadImpl.cpp.

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

void OW_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 158 of file OW_ThreadImpl.hpp.

bool OW_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 86 of file OW_ThreadImpl.hpp.

Referenced by OW_NAMESPACE::RWLocker::getReadLock(), OW_NAMESPACE::RWLocker::getWriteLock(), OW_NAMESPACE::RWLocker::releaseReadLock(), and OW_NAMESPACE::sameId().

void OW_NAMESPACE::ThreadImpl::saveThreadInTLS void *  pTheThread  ) 
 

Definition at line 366 of file OW_ThreadImpl.cpp.

References initializeTheKey(), once_control, OW_THROW, and theKey.

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

void OW_NAMESPACE::ThreadImpl::sendSignalToThread Thread_t  threadID,
int  signo
 

Definition at line 377 of file OW_ThreadImpl.cpp.

References OW_THROW.

Referenced by OW_NAMESPACE::Thread::cooperativeCancel(), and OW_NAMESPACE::Thread::definitiveCancel().

int OW_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 315 of file OW_ThreadImpl.cpp.

void OW_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 82 of file OW_ThreadImpl.cpp.

References OW_NAMESPACE::Select::select(), and testCancel().

Referenced by mbExtThreadSleep(), OW_NAMESPACE::milliSleep(), OW_NAMESPACE::secSleep(), OW_NAMESPACE::OpenWBEM_ObjectManagerInstProv::shuttingDown(), OW_NAMESPACE::Thread::sleep(), and yield().

void OW_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 345 of file OW_ThreadImpl.cpp.

References initializeTheKey(), OW_NAMESPACE::Thread::m_cancelLock, OW_NAMESPACE::Thread::m_cancelRequested, once_control, and theKey.

Referenced by OW_NAMESPACE::noIntrWaitPid(), OW_NAMESPACE::Select::selectRWPoll(), OW_NAMESPACE::Select::selectRWSelect(), sleep(), OW_NAMESPACE::Thread::testCancel(), and yield().

UInt64 OW_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 300 of file OW_ThreadImpl.cpp.

References OW_THREAD_CONVERTER.

static void* OW_NAMESPACE::ThreadImpl::@0::threadStarter void *  arg  )  [static]
 

Definition at line 152 of file OW_ThreadImpl.cpp.

References OW_ASSERT.

Referenced by createThread().

void OW_NAMESPACE::ThreadImpl::yield  ) 
 

Voluntarily yield to the processor giving the next thread in the chain the opportunity to run.

Definition at line 131 of file OW_ThreadImpl.cpp.

References sleep(), and testCancel().

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


Variable Documentation

default_stack_size OW_NAMESPACE::ThreadImpl::g_theDefaultStackSize [static]
 

Definition at line 221 of file OW_ThreadImpl.cpp.

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

Definition at line 223 of file OW_ThreadImpl.cpp.

Referenced by CMPI_ThreadContext::getThreadContext(), saveThreadInTLS(), CMPI_ThreadContext::setContext(), and testCancel().

pthread_key_t OW_NAMESPACE::ThreadImpl::theKey [static]
 

Definition at line 224 of file OW_ThreadImpl.cpp.

Referenced by OW_NAMESPACE::IndexImpl::add(), OW_NAMESPACE::IndexImpl::find(), OW_NAMESPACE::IndexImpl::findFirst(), OW_NAMESPACE::IndexImpl::findNext(), OW_NAMESPACE::IndexImpl::findPrev(), initializeTheKey(), OW_NAMESPACE::IndexImpl::remove(), saveThreadInTLS(), CMPI_ThreadContext::setContext(), testCancel(), and OW_NAMESPACE::IndexImpl::update().


Generated on Thu Feb 9 09:18:00 2006 for openwbem by  doxygen 1.4.6