Main Page | Alphabetical List | Class List | File List | Class Members | File Members

Thread Class Reference

#include <thread.h>

List of all members.

Public Member Functions

 Thread (char *debugName)
 ~Thread ()
void Fork (VoidFunctionPtr func, int arg)
void Yield ()
void Suspend ()
void Finish ()
void Sleep (int sec)
void UnSleep ()
void CheckOverflow ()
void setStatus (ThreadStatus st)
char * getName ()
void Print ()
ThreadStatus GetStatus ()

Public Attributes

sigjmp_buf cbuff
int started
char which


Constructor & Destructor Documentation

Thread::Thread char *  debugName  ) 
 

Definition at line 40 of file thread.cc.

References JUST_CREATED, and started.

00041 { 00042 name = threadName; 00043 stackTop = NULL; 00044 stack = NULL; 00045 status = JUST_CREATED; 00046 started = 0; 00047 #ifdef USER_PROGRAM 00048 space = NULL; 00049 #endif 00050 }

Thread::~Thread  ) 
 

Definition at line 64 of file thread.cc.

References ASSERT, currentThread, DeallocBoundedArray(), DEBUG(), and StackSize.

00065 { 00066 DEBUG('t', "Deleting thread \"%s\"\n", name); 00067 00068 ASSERT(this != currentThread); 00069 if (stack != NULL) 00070 DeallocBoundedArray((char *) stack, StackSize * sizeof(int)); 00071 }


Member Function Documentation

void Thread::CheckOverflow  ) 
 

Definition at line 121 of file thread.cc.

References ASSERT, STACK_FENCEPOST, and StackSize.

00122 { 00123 if (stack != NULL) 00124 #ifdef HOST_SNAKE // Stacks grow upward on the Snakes 00125 ASSERT(stack[StackSize - 1] == STACK_FENCEPOST); 00126 #else 00127 ASSERT(*stack == STACK_FENCEPOST); 00128 #endif 00129 }

void Thread::Finish  ) 
 

Definition at line 147 of file thread.cc.

References ASSERT, currentThread, DEBUG(), getName(), interrupt, IntOff, Interrupt::SetLevel(), Suspend(), and threadToBeDestroyed.

00148 { 00149 (void) interrupt->SetLevel(IntOff); 00150 ASSERT(this == currentThread); 00151 00152 DEBUG('t', "Finishing thread \"%s\"\n", getName()); 00153 00154 threadToBeDestroyed = currentThread; 00155 Suspend();// invokes SWITCH 00156 // not reached 00157 }

void Thread::Fork VoidFunctionPtr  func,
int  arg
 

Definition at line 93 of file thread.cc.

References DEBUG(), interrupt, IntOff, IntStatus, Scheduler::ReadyToRun(), scheduler, Interrupt::SetLevel(), and VoidFunctionPtr.

Referenced by PingPong(), and ThreadTest1().

00094 { 00095 DEBUG('t', "Forking thread \"%s\" with func = 0x%x, arg = %d\n", name, (int) func, arg); 00096 00097 pfunc = func; 00098 StackAllocate(func, arg); 00099 00100 00101 IntStatus oldLevel = interrupt->SetLevel(IntOff); 00102 scheduler->ReadyToRun(this); 00103 (void) interrupt->SetLevel(oldLevel); 00104 }

char* Thread::getName  )  [inline]
 

Definition at line 110 of file thread.h.

Referenced by Finish(), Semaphore::P(), Machine::Run(), schedule(), Suspend(), Semaphore::V(), and Yield().

00110 { return (name); }

ThreadStatus Thread::GetStatus  )  [inline]
 

Definition at line 113 of file thread.h.

References ThreadStatus.

00113 { return status; }

void Thread::Print  )  [inline]
 

Definition at line 111 of file thread.h.

Referenced by ThreadPrint().

00111 { printf("%s, ", name); }

void Thread::setStatus ThreadStatus  st  )  [inline]
 

Definition at line 109 of file thread.h.

Referenced by Scheduler::ReadyToRun(), and schedule().

00109 { status = st; }

void Thread::Sleep int  sec  ) 
 

Definition at line 229 of file thread.cc.

References cbuff, currentThread, interrupt, IntOff, IntStatus, SCHED, and Interrupt::SetLevel().

00230 { 00231 IntStatus oldLevel = interrupt->SetLevel(IntOff); 00232 00233 // your code goes here 00234 // change the state and go on the sleep queue delta list 00235 00236 if (sigsetjmp(currentThread->cbuff, 1) == 0) // save the current context 00237 { 00238 currentThread = 0; // nothing is executing 00239 SCHED(); // schedule in the context of the main process 00240 } 00241 00242 interrupt->SetLevel(oldLevel); 00243 }

void Thread::Suspend  ) 
 

Definition at line 210 of file thread.cc.

References ASSERT, BLOCKED, cbuff, currentThread, DEBUG(), getName(), Interrupt::Idle(), interrupt, Scheduler::IsEmpty(), SCHED, and scheduler.

Referenced by Finish(), and Semaphore::P().

00211 { 00212 ASSERT(this == currentThread); 00213 00214 DEBUG('t', "Suspending thread \"%s\"\n", getName()); 00215 00216 status = BLOCKED; 00217 00218 while (scheduler->IsEmpty()) 00219 interrupt->Idle(); // no one to run, wait for an interrupt 00220 // call the scheduler of the main proc 00221 if (sigsetjmp(currentThread->cbuff, 1) == 0) // save state then jump 00222 { 00223 currentThread = 0; // can't be put on the ready list 00224 SCHED(); // schedule in the context of the main process 00225 } 00226 }

void Thread::UnSleep  ) 
 

Definition at line 245 of file thread.cc.

References interrupt, IntOff, IntStatus, and Interrupt::SetLevel().

00246 { 00247 IntStatus oldLevel = interrupt->SetLevel(IntOff); 00248 00249 // your code goes here 00250 // unsleep the thread and change its status 00251 interrupt->SetLevel(oldLevel); 00252 }

void Thread::Yield  ) 
 

Definition at line 177 of file thread.cc.

References ASSERT, cbuff, currentThread, DEBUG(), getName(), interrupt, IntOff, IntStatus, schedule(), and Interrupt::SetLevel().

Referenced by Interrupt::OneTick().

00178 { 00179 IntStatus oldLevel = interrupt->SetLevel(IntOff); 00180 00181 ASSERT(this == currentThread); 00182 00183 DEBUG('t', "Yielding thread \"%s\"\n", getName()); 00184 00185 if (sigsetjmp(currentThread->cbuff, 1) == 0) // save state then jump 00186 schedule(); 00187 00188 (void) interrupt->SetLevel(oldLevel); 00189 }


Member Data Documentation

sigjmp_buf Thread::cbuff
 

Definition at line 124 of file thread.h.

Referenced by schedule(), Sleep(), Suspend(), Scheduler::timerIntH(), and Yield().

int Thread::started
 

Definition at line 125 of file thread.h.

Referenced by schedule(), and Thread().

char Thread::which
 

Definition at line 126 of file thread.h.


The documentation for this class was generated from the following files:
Generated on Thu Sep 16 12:33:49 2004 for NachOS by doxygen 1.3.8