Main Page   Namespace List   Class Hierarchy   Alphabetical List   Compound List   File List   Namespace Members   Compound Members   File Members   Related Pages   Examples  

vpr::BaseThread Class Reference

This is used as the base class for all thread classes. More...

#include <BaseThread.h>

Inheritance diagram for vpr::BaseThread:

Inheritance graph
[legend]
Collaboration diagram for vpr::BaseThread:

Collaboration graph
[legend]
List of all members.

Public Types

enum  VPRThreadPriority { VPR_PRIORITY_LOW, VPR_PRIORITY_NORMAL, VPR_PRIORITY_HIGH, VPR_PRIORITY_URGENT }
enum  VPRThreadScope { VPR_LOCAL_THREAD, VPR_GLOBAL_THREAD }
enum  VPRThreadState { VPR_JOINABLE_THREAD, VPR_UNJOINABLE_THREAD }

Public Methods

 BaseThread ()
virtual ~BaseThread ()
virtual void setFunctor (BaseThreadFunctor *functorPtr)=0
 Sets the thread's functor--the code that will get executed. More...

virtual vpr::ReturnStatus start ()=0
 Starts the thread's execution. More...

TSTablegetTSTable ()
 Gets the Thread specific data table. More...

virtual int join (void **status=0)
 Causes the calling thread wait for the termination of this thread. More...

virtual int resume ()
 Resumes the execution of this thread (if it 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 current priority. More...

virtual int setPrio (VPRThreadPriority prio)
 Sets this thread's priority. More...

vpr::Int32 getTID ()
 Gets the "thread ID" of this vpr::BaseThread object. More...

bool valid ()
 Is this a valid thread? More...

virtual int kill (int signum)
 Sends the specified signal to this thread (not necessarily SIGKILL). More...

virtual void kill ()
 Kill (cancel) this thread. More...

virtual std::ostream & outStream (std::ostream &out)
 Ouputs the state of the object. More...


Static Public Methods

TSTablegetGlobalTSTable ()
 Get the Thread the global thread specific data table. More...


Protected Methods

void registerThread (bool succesfulCreation)
 After the object has been created, call this routine to complete initialization. More...

void createThreadId ()
 Initializes the state of the object. More...


Detailed Description

This is used as the base class for all thread classes.

Definition at line 72 of file BaseThread.h.


Member Enumeration Documentation

enum vpr::BaseThread::VPRThreadPriority
 

Enumeration values:
VPR_PRIORITY_LOW  The lowest possible priority.
VPR_PRIORITY_NORMAL  The most common priority.
VPR_PRIORITY_HIGH  Slightly higher priority.
VPR_PRIORITY_URGENT  The highest priority.

Definition at line 75 of file BaseThread.h.

00076    {
00077       VPR_PRIORITY_LOW,      
00078       VPR_PRIORITY_NORMAL,   
00079       VPR_PRIORITY_HIGH,     
00080       VPR_PRIORITY_URGENT    
00081    };

enum vpr::BaseThread::VPRThreadScope
 

Enumeration values:
VPR_LOCAL_THREAD 
VPR_GLOBAL_THREAD 

Definition at line 83 of file BaseThread.h.

00084    {
00085       VPR_LOCAL_THREAD,
00086       VPR_GLOBAL_THREAD
00087    };

enum vpr::BaseThread::VPRThreadState
 

Enumeration values:
VPR_JOINABLE_THREAD  The thread can be reattached later.
VPR_UNJOINABLE_THREAD  The thread cannot be attached with join().

Definition at line 89 of file BaseThread.h.

00090    {
00091       VPR_JOINABLE_THREAD,   
00092       VPR_UNJOINABLE_THREAD  
00093    };


Constructor & Destructor Documentation

vpr::BaseThread::BaseThread   [inline]
 

Definition at line 95 of file BaseThread.h.

Referenced by vpr::ThreadSGI::self, vpr::ThreadPosix::self, and vpr::ThreadNSPR::self.

00095                 : mThreadId(-1)
00096    {
00097       ;
00098    }

virtual vpr::BaseThread::~BaseThread   [inline, virtual]
 

Definition at line 100 of file BaseThread.h.

00101    {
00102       ;
00103    }


Member Function Documentation

virtual void vpr::BaseThread::setFunctor BaseThreadFunctor   functorPtr [pure virtual]
 

Sets the thread's functor--the code that will get executed.

Implemented in vpr::ThreadNSPR.

virtual vpr::ReturnStatus vpr::BaseThread::start   [pure virtual]
 

Starts the thread's execution.

Implemented in vpr::ThreadNSPR.

TSTable* vpr::BaseThread::getTSTable   [inline]
 

Gets the Thread specific data table.

NOTE: Users should NOT access the table directly instead, use vpr::TSObjectProxies.

Definition at line 117 of file BaseThread.h.

00118    {
00119       return &mTSTable;
00120    }

TSTable* vpr::BaseThread::getGlobalTSTable   [inline, static]
 

Get the Thread the global thread specific data table.

This table is shared by all threads that were not created by vpr.

Definition at line 126 of file BaseThread.h.

00127    {
00128       return &gTSTable;
00129    }

void vpr::BaseThread::registerThread bool    succesfulCreation [protected]
 

After the object has been created, call this routine to complete initialization.

Done this way, because I need to call this based on stuff that happens in derived class's constructor.

Precondition:
The thread manager should be lock()'ed before calling this function so that the addThread function can execute correctly
Postcondition:
Thread is setup correctly to run. The thread has been registered with the system. Creates the thread's id (mThreadId)
Parameters:
successfulCreation  Did the thread get created correctly

Definition at line 77 of file BaseThread.cpp.

References createThreadId.

Referenced by vpr::ThreadSGI::start, vpr::ThreadPosix::start, vpr::ThreadNSPR::start, and vpr::ThreadPosix::startThread.

00078 {
00079    if(succesfulCreation)   // Succeed
00080    {
00081       createThreadId();
00082       ThreadManager::instance()->addThread(this); // Add the thread to the table
00083    }
00084    else
00085    {
00086       mThreadId = -1;      // We have an invalid thread
00087    }
00088 }

virtual int vpr::BaseThread::join void **    status = 0 [inline, virtual]
 

Causes the calling thread wait for the termination of this thread.

Postcondition:
The caller blocks until this thread finishes its execution (i.e., calls the exit() method). This routine may return immediately if this thread has already exited.
Parameters:
status  Current state of the terminating thread when that thread calls the exit routine (optional).
Returns:
0 is returned if this thread is "joined" successfully.
-1 is returned on an error condition.

Reimplemented in vpr::ThreadNSPR.

Definition at line 202 of file BaseThread.h.

00203    {
00204       boost::ignore_unused_variable_warning(status);
00205       return -1;
00206    }

virtual int vpr::BaseThread::resume void    [inline, virtual]
 

Resumes the execution of this thread (if it was previously suspended using suspend()).

Returns:
0 is returned if this thread resumes execuation successfully.
-1 is returned otherwise.

Reimplemented in vpr::ThreadNSPR.

Definition at line 215 of file BaseThread.h.

00216    {
00217       return -1;
00218    }

virtual int vpr::BaseThread::suspend void    [inline, virtual]
 

Suspends the execution of this thread.

Returns:
0 is returned if this thread is suspended successfully.
-1 is returned otherwise.

Reimplemented in vpr::ThreadNSPR.

Definition at line 226 of file BaseThread.h.

00227    {
00228       return -1;
00229    }

virtual int vpr::BaseThread::getPrio VPRThreadPriority   prio [inline, virtual]
 

Gets this thread's current priority.

Precondition:
None.
Postcondition:
The priority of this thread is returned in the integer pointer variable.
Parameters:
prio  Pointer to an int variable that will have the thread's priority stored in it.
Returns:
0 is returned if the priority was retrieved successfully.
-1 is returned if the priority could not be read.

Reimplemented in vpr::ThreadNSPR.

Definition at line 244 of file BaseThread.h.

00245    {
00246       boost::ignore_unused_variable_warning(prio);
00247       return -1;
00248    }

virtual int vpr::BaseThread::setPrio VPRThreadPriority    prio [inline, virtual]
 

Sets this thread's priority.

Parameters:
prio  The new priority for this thread.
Returns:
0 is returned if this thread's priority was set successfully.
-1 is returned otherwise.

Reimplemented in vpr::ThreadNSPR.

Definition at line 258 of file BaseThread.h.

00259    {
00260       boost::ignore_unused_variable_warning(prio);
00261       return -1;
00262    }

vpr::Int32 vpr::BaseThread::getTID   [inline]
 

Gets the "thread ID" of this vpr::BaseThread object.

This is a unique integer value assigned when the thread was created.

Returns:
-1 is returned if this is a bad thread. This usually means that there was a reation error.
Otherwise, the value returned is this thread's ID.

Definition at line 272 of file BaseThread.h.

Referenced by vpr::ThreadNSPR::start.

00273    {
00274       return mThreadId;
00275    }

bool vpr::BaseThread::valid   [inline]
 

Is this a valid thread?

Returns:
true is returned if this object represents a thread that has been spawned correctly.
Note:
A true value may be returned before the spawned thread begins executing. This is due to the way that the operating system schedules a newly created thread. However, true is returned if and only if the thread has been spawned successfully.

Definition at line 288 of file BaseThread.h.

00289    {
00290       return (mThreadId != -1);
00291    }

virtual int vpr::BaseThread::kill int    signum [inline, virtual]
 

Sends the specified signal to this thread (not necessarily SIGKILL).

Postcondition:
This thread receives the specified signal.
Parameters:
signum  The signal to send to the specified thread.
Returns:
0 is returned if the thread was sent the given signal.
-1 is returned if an error occurred.

Reimplemented in vpr::ThreadNSPR.

Definition at line 303 of file BaseThread.h.

00304    {
00305       boost::ignore_unused_variable_warning(signum);
00306       return -1;
00307    }

virtual void vpr::BaseThread::kill   [inline, virtual]
 

Kill (cancel) this thread.

Precondition:
None.
Postcondition:
This thread is cancelled. Immediate cancellation is not guaranteed.

Reimplemented in vpr::ThreadNSPR.

Definition at line 315 of file BaseThread.h.

00316    {;}

virtual std::ostream& vpr::BaseThread::outStream std::ostream &    out [inline, virtual]
 

Ouputs the state of the object.

Reimplemented in vpr::ThreadNSPR.

Definition at line 321 of file BaseThread.h.

00322    {
00323       out.setf(std::ios::right);
00324       out << std::setw(3) << mThreadId;
00325       out.unsetf(std::ios::right);
00326       return out;
00327    }

void vpr::BaseThread::createThreadId   [inline, protected]
 

Initializes the state of the object.

Definition at line 333 of file BaseThread.h.

Referenced by registerThread.

00334    {
00335       mThreadId = getNextThreadId();
00336    }


The documentation for this class was generated from the following files:
Generated on Sun May 2 14:47:12 2004 for VR Juggler Portable Runtime by doxygen1.2.14 written by Dimitri van Heesch, © 1997-2002