#include <thread.h>
Public Methods | |
| Thread (char *debugName) | |
| ~Thread () | |
| void | Fork (VoidFunctionPtr func, int arg) |
| void | Yield () |
| void | Sleep () |
| void | Finish () |
| void | CheckOverflow () |
| void | setStatus (ThreadStatus st) |
| char * | getName () |
| void | Print () |
Private Methods | |
| void | StackAllocate (VoidFunctionPtr func, int arg) |
Private Attributes | |
| int * | stackTop |
| int | machineState [MachineStateSize] |
| int * | stack |
| ThreadStatus | status |
| char * | name |
|
|
Definition at line 35 of file thread.cc. References JUST_CREATED, name, NULL, stack, stackTop, and status.
|
|
|
Definition at line 58 of file thread.cc. References ASSERT, DeallocBoundedArray, DEBUG, name, NULL, and stack.
|
|
|
Definition at line 117 of file thread.cc. References ASSERT, NULL, stack, and STACK_FENCEPOST. Referenced by Scheduler::Run.
00118 {
00119 if (stack != NULL)
00120 #ifdef HOST_SNAKE // Stacks grow upward on the Snakes
00121 ASSERT(stack[StackSize - 1] == STACK_FENCEPOST);
00122 #else
00123 ASSERT(*stack == (int) STACK_FENCEPOST);
00124 #endif
00125 }
|
|
|
Definition at line 144 of file thread.cc. References ASSERT, DEBUG, getName, IntOff, and Sleep.
|
|
||||||||||||
|
Definition at line 88 of file thread.cc. References DEBUG, IntOff, IntStatus, name, StackAllocate, and VoidFunctionPtr. Referenced by PostOffice::PostOffice, and ThreadTest.
00089 {
00090 DEBUG('t', "Forking thread \"%s\" with func = 0x%x, arg = %d\n",
00091 name, (int) func, arg);
00092
00093 StackAllocate(func, arg);
00094
00095 IntStatus oldLevel = interrupt->SetLevel(IntOff);
00096 scheduler->ReadyToRun(this); // ReadyToRun assumes that interrupts
00097 // are disabled!
00098 (void) interrupt->SetLevel(oldLevel);
00099 }
|
|
|
Definition at line 102 of file thread.h. Referenced by Finish, Scheduler::ReadyToRun, Scheduler::Run, Sleep, and Yield.
00102 { return (name); }
|
|
|
Definition at line 103 of file thread.h. References name. Referenced by ThreadPrint.
00103 { printf("%s, ", name); }
|
|
|
Definition at line 101 of file thread.h. References status, and ThreadStatus. Referenced by Initialize, Scheduler::ReadyToRun, and Scheduler::Run.
00101 { status = st; }
|
|
|
Definition at line 212 of file thread.cc. References ASSERT, BLOCKED, DEBUG, getName, IntOff, NULL, and status. Referenced by Finish.
00213 {
00214 Thread *nextThread;
00215
00216 ASSERT(this == currentThread);
00217 ASSERT(interrupt->getLevel() == IntOff);
00218
00219 DEBUG('t', "Sleeping thread \"%s\"\n", getName());
00220
00221 status = BLOCKED;
00222 while ((nextThread = scheduler->FindNextToRun()) == NULL)
00223 interrupt->Idle(); // no one to run, wait for an interrupt
00224
00225 scheduler->Run(nextThread); // returns when we've been signalled
00226 }
|
|
||||||||||||
|
Definition at line 253 of file thread.cc. References AllocBoundedArray, InterruptEnable, machineState, stack, STACK_FENCEPOST, stackTop, ThreadFinish, ThreadRoot, and VoidFunctionPtr. Referenced by Fork.
00254 {
00255 stack = (int *) AllocBoundedArray(StackSize * sizeof(int));
00256
00257 #ifdef HOST_SNAKE
00258 // HP stack works from low addresses to high addresses
00259 stackTop = stack + 16; // HP requires 64-byte frame marker
00260 stack[StackSize - 1] = STACK_FENCEPOST;
00261 #else
00262 // i386 & MIPS & SPARC stack works from high addresses to low addresses
00263 #ifdef HOST_SPARC
00264 // SPARC stack must contains at least 1 activation record to start with.
00265 stackTop = stack + StackSize - 96;
00266 #else // HOST_MIPS || HOST_i386
00267 stackTop = stack + StackSize - 4; // -4 to be on the safe side!
00268 #ifdef HOST_i386
00269 // the 80386 passes the return address on the stack. In order for
00270 // SWITCH() to go to ThreadRoot when we switch to this thread, the
00271 // return addres used in SWITCH() must be the starting address of
00272 // ThreadRoot.
00273 *(--stackTop) = (int)ThreadRoot;
00274 #endif
00275 #endif // HOST_SPARC
00276 *stack = STACK_FENCEPOST;
00277 #endif // HOST_SNAKE
00278
00279 machineState[PCState] = (int) ThreadRoot;
00280 machineState[StartupPCState] = (int) InterruptEnable;
00281 machineState[InitialPCState] = (int) func;
00282 machineState[InitialArgState] = arg;
00283 machineState[WhenDonePCState] = (int) ThreadFinish;
00284 }
|
|
|
Definition at line 175 of file thread.cc. References ASSERT, DEBUG, getName, IntOff, IntStatus, and NULL.
00176 {
00177 Thread *nextThread;
00178 IntStatus oldLevel = interrupt->SetLevel(IntOff);
00179
00180 ASSERT(this == currentThread);
00181
00182 DEBUG('t', "Yielding thread \"%s\"\n", getName());
00183
00184 nextThread = scheduler->FindNextToRun();
00185 if (nextThread != NULL) {
00186 scheduler->ReadyToRun(this);
00187 scheduler->Run(nextThread);
00188 }
00189 (void) interrupt->SetLevel(oldLevel);
00190 }
|
|
|
Definition at line 81 of file thread.h. Referenced by StackAllocate. |
|
|
|
|
|
Definition at line 108 of file thread.h. Referenced by CheckOverflow, StackAllocate, Thread, and ~Thread. |
|
|
Definition at line 80 of file thread.h. Referenced by StackAllocate, and Thread. |
|
|
|
1.2.14 written by Dimitri van Heesch,
© 1997-2002