#include <vpr/Thread/Thread.h>
Inheritance diagram for vpr::ThreadNSPR:


Public Member Functions | |
| ThreadNSPR (VPRThreadPriority priority=VPR_PRIORITY_NORMAL, VPRThreadScope scope=VPR_GLOBAL_THREAD, VPRThreadState state=VPR_JOINABLE_THREAD, PRUint32 stack_size=0) | |
| Non-spawning constructor. | |
| ThreadNSPR (thread_func_t func, void *arg=NULL, VPRThreadPriority priority=VPR_PRIORITY_NORMAL, VPRThreadScope scope=VPR_GLOBAL_THREAD, VPRThreadState state=VPR_JOINABLE_THREAD, PRUint32 stack_size=0) | |
| Spawning constructor. | |
| ThreadNSPR (BaseThreadFunctor *functor_ptr, VPRThreadPriority priority=VPR_PRIORITY_NORMAL, VPRThreadScope scope=VPR_GLOBAL_THREAD, VPRThreadState state=VPR_JOINABLE_THREAD, PRUint32 stack_size=0) | |
| Spawning constructor (functor version). | |
| virtual | ~ThreadNSPR () |
| Destructor. | |
| virtual void | setFunctor (BaseThreadFunctor *functorPtr) |
| Sets the functor that this thread will execute. | |
| virtual vpr::ReturnStatus | start () |
| Creates a new thread that will execute this thread's functor. | |
| virtual int | join (void **status=NULL) |
| Makes the calling thread wait for the termination of this thread. | |
| virtual int | resume () |
| Resumes the execution of a thread that was previously suspended using suspend(). | |
| virtual int | suspend () |
| Suspends the execution of this thread. | |
| virtual int | getPrio (VPRThreadPriority *prio) |
| Gets this thread's priority. | |
| virtual int | setPrio (VPRThreadPriority prio) |
| Sets this thread's priority. | |
| virtual int | kill (int signum) |
| Sends the specified signal to this thread (not necessarily SIGKILL). | |
| virtual void | kill () |
| Kills (cancels) this thread. | |
| virtual std::ostream & | outStream (std::ostream &out) |
| Provides a way of printing the process ID neatly. | |
Static Public Member Functions | |
| static Thread * | self () |
| Gets a pointer to the thread we are in. | |
| static void | yield () |
| Yields execution of the calling thread to allow a different blocked thread to execute. | |
Classes | |
| struct | staticWrapper |
This works by recieving a function in the constructor that is the function to call when the new thread is created. The function is stored internally to the class, then the class is "boot-strapped" by spawning a call to the startThread() function with in turn will call the previously set thread function.
This is typedef'd to vpr::Thread.
Definition at line 83 of file ThreadNSPR.h.
| vpr::ThreadNSPR::ThreadNSPR | ( | VPRThreadPriority | priority = VPR_PRIORITY_NORMAL, |
|
| VPRThreadScope | scope = VPR_GLOBAL_THREAD, |
|||
| VPRThreadState | state = VPR_JOINABLE_THREAD, |
|||
| PRUint32 | stack_size = 0 | |||
| ) |
Non-spawning constructor.
This will not start a thread.
Definition at line 60 of file ThreadNSPR.cpp.
00062 : mThread(NULL) 00063 , mUserThreadFunctor(NULL) 00064 , mDeleteFunctor(false) 00065 , mStartFunctor(NULL) 00066 , mPriority(priority) 00067 , mScope(scope) 00068 , mState(state) 00069 , mStackSize(stackSize) 00070 { 00071 }
| vpr::ThreadNSPR::ThreadNSPR | ( | thread_func_t | func, | |
| void * | arg = NULL, |
|||
| VPRThreadPriority | priority = VPR_PRIORITY_NORMAL, |
|||
| VPRThreadScope | scope = VPR_GLOBAL_THREAD, |
|||
| VPRThreadState | state = VPR_JOINABLE_THREAD, |
|||
| PRUint32 | stack_size = 0 | |||
| ) |
Spawning constructor.
This will start a new thread that will execute the specified function.
Definition at line 75 of file ThreadNSPR.cpp.
References setFunctor(), and start().
00078 : mThread(NULL) 00079 , mUserThreadFunctor(NULL) 00080 , mDeleteFunctor(false) 00081 , mStartFunctor(NULL) 00082 , mPriority(priority) 00083 , mScope(scope) 00084 , mState(state) 00085 , mStackSize(stackSize) 00086 { 00087 mDeleteFunctor = true; 00088 setFunctor(new ThreadNonMemberFunctor(func, arg)); 00089 start(); 00090 }
| vpr::ThreadNSPR::ThreadNSPR | ( | BaseThreadFunctor * | functor_ptr, | |
| VPRThreadPriority | priority = VPR_PRIORITY_NORMAL, |
|||
| VPRThreadScope | scope = VPR_GLOBAL_THREAD, |
|||
| VPRThreadState | state = VPR_JOINABLE_THREAD, |
|||
| PRUint32 | stack_size = 0 | |||
| ) |
Spawning constructor (functor version).
This will start a new thread that will execute the specified functor.
Definition at line 94 of file ThreadNSPR.cpp.
References setFunctor(), and start().
00097 : mThread(NULL) 00098 , mUserThreadFunctor(NULL) 00099 , mDeleteFunctor(false) 00100 , mStartFunctor(NULL) 00101 , mPriority(priority) 00102 , mScope(scope) 00103 , mState(state) 00104 , mStackSize(stackSize) 00105 { 00106 setFunctor(functorPtr); 00107 start(); 00108 }
| vpr::ThreadNSPR::~ThreadNSPR | ( | ) | [virtual] |
Destructor.
Definition at line 111 of file ThreadNSPR.cpp.
References vpr::BaseThread::unregisterThread().
00112 { 00113 ThreadManager::instance()->lock(); 00114 { 00115 unregisterThread(); 00116 } 00117 ThreadManager::instance()->unlock(); 00118 00119 if ( NULL != mStartFunctor ) 00120 { 00121 delete mStartFunctor; 00122 mStartFunctor = NULL; 00123 } 00124 00125 if ( mDeleteFunctor ) 00126 { 00127 delete mUserThreadFunctor; 00128 mUserThreadFunctor = NULL; 00129 } 00130 }
| void vpr::ThreadNSPR::setFunctor | ( | BaseThreadFunctor * | functorPtr | ) | [virtual] |
Sets the functor that this thread will execute.
Implements vpr::BaseThread.
Definition at line 132 of file ThreadNSPR.cpp.
References vpr::BaseThreadFunctor::isValid(), and vprASSERT.
Referenced by ThreadNSPR().
00133 { 00134 vprASSERT(mThread == NULL && "Thread already running"); 00135 vprASSERT(functorPtr->isValid()); 00136 00137 mUserThreadFunctor = functorPtr; 00138 }
| vpr::ReturnStatus vpr::ThreadNSPR::start | ( | ) | [virtual] |
Creates a new thread that will execute this thread's functor.
Implements vpr::BaseThread.
Definition at line 141 of file ThreadNSPR.cpp.
References vpr::CondVarNSPR::acquire(), vpr::ReturnStatus::Fail, vpr::BaseThread::getTID(), vpr::BaseThreadFunctor::isValid(), vpr::NSPR_PrintError(), vpr::BaseThread::registerThread(), vpr::CondVarNSPR::release(), vpr::ReturnStatus::setCode(), vpr::ReturnStatus::Succeed, vprASSERT, vpr::vprThreadFunctorFunction(), and vpr::CondVarNSPR::wait().
Referenced by ThreadNSPR().
00142 { 00143 vpr::ReturnStatus status; 00144 00145 if ( NULL != mThread ) 00146 { 00147 vprASSERT(false && "Thread already running"); 00148 status.setCode(vpr::ReturnStatus::Fail); 00149 } 00150 else if ( NULL == mUserThreadFunctor ) 00151 { 00152 vprASSERT(false && "No functor set"); 00153 status.setCode(vpr::ReturnStatus::Fail); 00154 } 00155 else 00156 { 00157 PRThreadPriority nspr_prio; 00158 PRThreadScope nspr_scope; 00159 PRThreadState nspr_state; 00160 00161 nspr_prio = vprThreadPriorityToNSPR(mPriority); 00162 nspr_scope = vprThreadScopeToNSPR(mScope); 00163 nspr_state = vprThreadStateToNSPR(mState); 00164 00165 vprASSERT(mUserThreadFunctor->isValid()); 00166 00167 // Store the member functor and create the functor for spawning to our 00168 // start routine. 00169 mStartFunctor = 00170 new ThreadMemberFunctor<ThreadNSPR>(this, &ThreadNSPR::startThread, 00171 NULL); 00172 00173 // Finally create the thread. 00174 // - On success --> The start method registers the actual thread info 00175 mThreadStartCompleted = false; // Initialize registration flag (uses cond var for this) 00176 PRThread* ret_thread = 00177 PR_CreateThread(PR_USER_THREAD, vprThreadFunctorFunction, 00178 (void*) mStartFunctor, nspr_prio, nspr_scope, 00179 nspr_state, (PRUint32) mStackSize); 00180 00181 // Inform the caller if the thread was not created successfully. 00182 if ( NULL == ret_thread ) 00183 { 00184 ThreadManager::instance()->lock(); 00185 { 00186 registerThread(false); 00187 } 00188 ThreadManager::instance()->unlock(); 00189 00190 NSPR_PrintError("vpr::ThreadNSPR::spawn() - Cannot create thread"); 00191 status.setCode(vpr::ReturnStatus::Fail); 00192 } 00193 else 00194 { 00195 // start thread will register the thread, so let's wait for it 00196 // -- Wait for registration to complete 00197 mThreadStartCondVar.acquire(); 00198 { 00199 // While not desired state (ie. register completed) 00200 while ( !mThreadStartCompleted ) 00201 { 00202 mThreadStartCondVar.wait(); 00203 } 00204 } 00205 mThreadStartCondVar.release(); 00206 // ASSERT: Thread has completed registration 00207 vprASSERT(NULL != mThread && "Thread registration failed"); 00208 vprASSERT(-1 != getTID() && "Thread id is invalid for successful thread"); 00209 00210 // Set the return code to success 00211 status.setCode(vpr::ReturnStatus::Succeed); 00212 } 00213 } 00214 00215 return status; 00216 }
| int vpr::ThreadNSPR::join | ( | void ** | status = NULL |
) | [virtual] |
Makes the calling thread wait for the termination of this thread.
Reimplemented from vpr::BaseThread.
Definition at line 218 of file ThreadNSPR.cpp.
00219 { 00220 boost::ignore_unused_variable_warning(status); 00221 return PR_JoinThread(mThread); 00222 }
| virtual int vpr::ThreadNSPR::resume | ( | ) | [inline, virtual] |
Resumes the execution of a thread that was previously suspended using suspend().
Reimplemented from vpr::BaseThread.
Definition at line 167 of file ThreadNSPR.h.
| virtual int vpr::ThreadNSPR::suspend | ( | void | ) | [inline, virtual] |
Suspends the execution of this thread.
Reimplemented from vpr::BaseThread.
Definition at line 182 of file ThreadNSPR.h.
| virtual int vpr::ThreadNSPR::getPrio | ( | VPRThreadPriority * | prio | ) | [inline, virtual] |
Gets this thread's priority.
| prio | Pointer to an int variable that will have the thread's priority stored in it. |
Definition at line 201 of file ThreadNSPR.h.
00202 { 00203 *prio = nsprThreadPriorityToVPR(PR_GetThreadPriority(mThread)); 00204 00205 return 0; 00206 }
| int vpr::ThreadNSPR::setPrio | ( | VPRThreadPriority | prio | ) | [virtual] |
Sets this thread's priority.
| prio | The new priority for this thread. |
Definition at line 288 of file ThreadNSPR.cpp.
00289 { 00290 int retval(0); 00291 00292 if ( prio > 3 ) 00293 { 00294 retval = -1; 00295 } 00296 else 00297 { 00298 PR_SetThreadPriority(mThread, vprThreadPriorityToNSPR(prio)); 00299 } 00300 00301 return retval; 00302 }
| virtual int vpr::ThreadNSPR::kill | ( | int | signum | ) | [inline, virtual] |
Sends the specified signal to this thread (not necessarily SIGKILL).
| signum | The signal to send to the specified thread. |
Reimplemented from vpr::BaseThread.
Definition at line 233 of file ThreadNSPR.h.
| virtual void vpr::ThreadNSPR::kill | ( | ) | [inline, virtual] |
Kills (cancels) this thread.
Reimplemented from vpr::BaseThread.
Definition at line 253 of file ThreadNSPR.h.
| Thread * vpr::ThreadNSPR::self | ( | ) | [static] |
Gets a pointer to the thread we are in.
A non-NULL value is the pointer to the thread that we are running within.
Definition at line 224 of file ThreadNSPR.cpp.
References vpr::ThreadKeyNSPR::getspecific(), and vprASSERT.
00225 { 00226 vprASSERT((statics.mStaticsInitialized==1221) && "Trying to call vpr::ThreadNSPR::self before statics are initialized. Don't do that"); 00227 00228 Thread* my_thread; 00229 threadIdKey().getspecific((void**)&my_thread); 00230 00231 return my_thread; 00232 }
| static void vpr::ThreadNSPR::yield | ( | ) | [inline, static] |
Yields execution of the calling thread to allow a different blocked thread to execute.
Definition at line 273 of file ThreadNSPR.h.
| virtual std::ostream& vpr::ThreadNSPR::outStream | ( | std::ostream & | out | ) | [virtual] |
1.5.1