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


Public Methods | |
| ThreadNSPR (VPRThreadPriority priority=VPR_PRIORITY_NORMAL, VPRThreadScope scope=VPR_GLOBAL_THREAD, VPRThreadState state=VPR_JOINABLE_THREAD, PRUint32 stack_size=0) | |
| Non-spawning constructor. More... | |
| 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. More... | |
| 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). More... | |
| virtual | ~ThreadNSPR () |
| Destructor. More... | |
| virtual void | setFunctor (BaseThreadFunctor *functorPtr) |
| Sets the functor that this thread will execute. More... | |
| virtual vpr::ReturnStatus | start () |
| Creates a new thread that will execute this thread's functor. More... | |
| virtual int | join (void **status=NULL) |
| Makes the calling thread wait for the termination of this thread. More... | |
| virtual int | resume () |
| Resumes the execution of a thread that was previously suspended using suspend(). More... | |
| virtual int | suspend () |
| Suspends the execution of this thread. More... | |
| virtual int | getPrio (VPRThreadPriority *prio) |
| Gets this thread's priority. More... | |
| virtual int | setPrio (VPRThreadPriority prio) |
| Sets this thread's priority. More... | |
| virtual int | kill (int signum) |
| Sends the specified signal to this thread (not necessarily SIGKILL). More... | |
| virtual void | kill () |
| Kills (cancels) this thread. More... | |
| virtual std::ostream & | outStream (std::ostream &out) |
| Provides a way of printing the process ID neatly. More... | |
Static Public Methods | |
| BaseThread * | self (void) |
| Gets a pointer to the thread we are in. More... | |
| void | yield (void) |
| Yields execution of the calling thread to allow a different blocked thread to execute. More... | |
Definition at line 75 of file ThreadNSPR.h.
|
||||||||||||||||||||
|
Non-spawning constructor. This will not start a thread. Definition at line 59 of file ThreadNSPR.cpp.
00061 : mThread(NULL), mUserThreadFunctor(NULL), mPriority(priority),
00062 mScope(scope), mState(state), mStackSize(stackSize)
00063 {
00064 }
|
|
||||||||||||||||||||||||||||
|
Spawning constructor. This will start a new thread that will execute the specified function. Definition at line 68 of file ThreadNSPR.cpp. References setFunctor, start, and vpr::thread_func_t.
00071 : mThread(NULL), mUserThreadFunctor(NULL), mPriority(priority),
00072 mScope(scope), mState(state), mStackSize(stackSize)
00073 {
00074 // XXX: Memory leak.
00075 setFunctor(new ThreadNonMemberFunctor(func, arg));
00076 start();
00077 }
|
|
||||||||||||||||||||||||
|
Spawning constructor (functor version). This will start a new thread that will execute the specified functor. Definition at line 81 of file ThreadNSPR.cpp. References setFunctor, and start.
00084 : mThread(NULL), mUserThreadFunctor(NULL), mPriority(priority),
00085 mScope(scope), mState(state), mStackSize(stackSize)
00086 {
00087 setFunctor(functorPtr);
00088 start();
00089 }
|
|
|
Destructor.
Definition at line 92 of file ThreadNSPR.cpp.
00093 {
00094 ;
00095 }
|
|
|
Sets the functor that this thread will execute.
Implements vpr::BaseThread. Definition at line 97 of file ThreadNSPR.cpp. References vprASSERT. Referenced by ThreadNSPR.
|
|
|
Creates a new thread that will execute this thread's functor.
Implements vpr::BaseThread. Definition at line 106 of file ThreadNSPR.cpp. References vpr::CondVarNSPR::acquire, vpr::ReturnStatus::Fail, vpr::BaseThread::getTID, 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.
00107 {
00108 vpr::ReturnStatus status;
00109
00110 if ( NULL != mThread )
00111 {
00112 vprASSERT(false && "Thread already running");
00113 status.setCode(vpr::ReturnStatus::Fail);
00114 }
00115 else if ( NULL == mUserThreadFunctor )
00116 {
00117 vprASSERT(false && "No functor set");
00118 status.setCode(vpr::ReturnStatus::Fail);
00119 }
00120 else
00121 {
00122 PRThreadPriority nspr_prio;
00123 PRThreadScope nspr_scope;
00124 PRThreadState nspr_state;
00125
00126 nspr_prio = vprThreadPriorityToNSPR(mPriority);
00127 nspr_scope = vprThreadScopeToNSPR(mScope);
00128 nspr_state = vprThreadStateToNSPR(mState);
00129
00130 vprASSERT(mUserThreadFunctor->isValid());
00131
00132 // Store the member functor and create the functor for spawning to our
00133 // start routine.
00134 // XXX: Memory leak.
00135 ThreadMemberFunctor<ThreadNSPR>* start_functor =
00136 new ThreadMemberFunctor<ThreadNSPR>(this, &ThreadNSPR::startThread,
00137 NULL);
00138
00139 // Finally create the thread.
00140 // - On success --> The start method registers the actual thread info
00141 mThreadStartCompleted = false; // Initialize registration flag (uses cond var for this)
00142 PRThread* ret_thread = PR_CreateThread(PR_USER_THREAD, vprThreadFunctorFunction,
00143 (void*) start_functor, nspr_prio, nspr_scope,
00144 nspr_state, (PRUint32) mStackSize);
00145
00146 // Inform the caller if the thread was not created successfully.
00147 if ( NULL == ret_thread )
00148 {
00149 ThreadManager::instance()->lock();
00150 {
00151 registerThread(false);
00152 }
00153 ThreadManager::instance()->unlock();
00154
00155 NSPR_PrintError("vpr::ThreadNSPR::spawn() - Cannot create thread");
00156 status.setCode(vpr::ReturnStatus::Fail);
00157 }
00158 else
00159 {
00160 // start thread will register the thread, so let's wait for it
00161 // -- Wait for registration to complete
00162 mThreadStartCondVar.acquire();
00163 {
00164 while ( !mThreadStartCompleted ) // While not desired state (ie. register completed)
00165 { mThreadStartCondVar.wait();}
00166 }
00167 mThreadStartCondVar.release();
00168 // ASSERT: Thread has completed registration
00169 vprASSERT(NULL != mThread && "Thread registration failed");
00170 vprASSERT(-1 != getTID() && "Thread id is invalid for successful thread");
00171
00172 // Set the return code to success
00173 status.setCode(vpr::ReturnStatus::Succeed);
00174 }
00175 }
00176
00177 return status;
00178 }
|
|
|
Makes the calling thread wait for the termination of this thread.
Reimplemented from vpr::BaseThread. Definition at line 180 of file ThreadNSPR.cpp.
00181 {
00182 boost::ignore_unused_variable_warning(status);
00183 return PR_JoinThread(mThread);
00184 }
|
|
|
Resumes the execution of a thread that was previously suspended using suspend().
Reimplemented from vpr::BaseThread. Definition at line 160 of file ThreadNSPR.h.
00161 {
00162 // return kill(SIGCONT);
00163 return -1;
00164 }
|
|
|
Suspends the execution of this thread.
Reimplemented from vpr::BaseThread. Definition at line 176 of file ThreadNSPR.h.
00177 {
00178 // return kill(SIGSTOP);
00179 return -1;
00180 }
|
|
|
Gets this thread's priority.
Reimplemented from vpr::BaseThread. Definition at line 195 of file ThreadNSPR.h.
00196 {
00197 *prio = nsprThreadPriorityToVPR(PR_GetThreadPriority(mThread));
00198
00199 return 0;
00200 }
|
|
|
Sets this thread's priority.
Reimplemented from vpr::BaseThread. Definition at line 235 of file ThreadNSPR.cpp.
00236 {
00237 int retval(0);
00238
00239 if ( prio > 3 )
00240 {
00241 retval = -1;
00242 }
00243 else
00244 {
00245 PR_SetThreadPriority(mThread, vprThreadPriorityToNSPR(prio));
00246 }
00247
00248 return retval;
00249 }
|
|
|
Sends the specified signal to this thread (not necessarily SIGKILL).
Reimplemented from vpr::BaseThread. Definition at line 229 of file ThreadNSPR.h.
00230 {
00231 boost::ignore_unused_variable_warning(signum);
00232 return -1;
00233 }
|
|
|
Kills (cancels) this thread.
Reimplemented from vpr::BaseThread. Definition at line 250 of file ThreadNSPR.h.
00251 {
00252 }
|
|
|
Gets a pointer to the thread we are in.
Definition at line 186 of file ThreadNSPR.cpp. References vpr::BaseThread::BaseThread, and vprASSERT.
00187 {
00188 vprASSERT((statics.mStaticsInitialized==1221) && "Trying to call vpr::ThreadNSPR::self before statics are initialized. Don't do that");
00189
00190 BaseThread* my_thread;
00191 threadIdKey().getspecific((void**)&my_thread);
00192
00193 return my_thread;
00194 }
|
|
|
Yields execution of the calling thread to allow a different blocked thread to execute.
Definition at line 270 of file ThreadNSPR.h.
00271 {
00272 PR_Sleep(PR_INTERVAL_NO_WAIT);
00273 }
|
|
|
Provides a way of printing the process ID neatly.
Reimplemented from vpr::BaseThread. Definition at line 278 of file ThreadNSPR.h.
00279 {
00280 out.setf(std::ios::right);
00281 out << std::setw(7) << std::setfill('0') << getpid() << "/";
00282 out.unsetf(std::ios::right);
00283 BaseThread::outStream(out);
00284 out << std::setfill(' ');
00285 return out;
00286 }
|
1.2.14 written by Dimitri van Heesch,
© 1997-2002