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

Interrupt Class Reference

#include <interrupt.h>

List of all members.

Public Member Functions

 Interrupt ()
 ~Interrupt ()
IntStatus SetLevel (IntStatus level)
void Enable ()
IntStatus getLevel ()
void Idle ()
void Halt ()
void YieldOnReturn ()
MachineStatus getStatus ()
void setStatus (MachineStatus st)
void DumpState ()
void Schedule (VoidFunctionPtr handler, int arg, int when, IntType type)
void OneTick ()

Public Attributes

IntStatus level


Constructor & Destructor Documentation

Interrupt::Interrupt  ) 
 

Definition at line 67 of file interrupt.cc.

References FALSE, IntOff, level, and SystemMode.

00068 { 00069 level = IntOff; 00070 pending = new List(); 00071 inHandler = FALSE; 00072 yieldOnReturn = FALSE; 00073 status = SystemMode; 00074 }

Interrupt::~Interrupt  ) 
 

Definition at line 81 of file interrupt.cc.

References List::IsEmpty(), and List::Remove().

00082 { 00083 while (!pending->IsEmpty()) 00084 delete pending->Remove(); 00085 delete pending; 00086 }


Member Function Documentation

void Interrupt::DumpState  ) 
 

Definition at line 372 of file interrupt.cc.

References level, List::Mapcar(), stats, and Statistics::totalTicks.

Referenced by Machine::Debugger().

00373 { 00374 printf("Time: %d, interrupts %s\n", stats->totalTicks, 00375 intLevelNames[level]); 00376 printf("Pending interrupts:\n"); 00377 fflush(stdout); 00378 pending->Mapcar(PrintPending); 00379 printf("End of pending interrupts\n"); 00380 fflush(stdout); 00381 }

void Interrupt::Enable  ) 
 

Definition at line 149 of file interrupt.cc.

References IntOn, and SetLevel().

Referenced by Initialize(), and schedule().

00150 { 00151 (void) SetLevel(IntOn); 00152 }

IntStatus Interrupt::getLevel  )  [inline]
 

Definition at line 86 of file interrupt.h.

References IntStatus.

00086 {return level;}// Return whether interrupts

MachineStatus Interrupt::getStatus  )  [inline]
 

Definition at line 98 of file interrupt.h.

References MachineStatus.

Referenced by PollFile().

00098 { return status; } // idle, kernel, user

void Interrupt::Halt  ) 
 

Definition at line 255 of file interrupt.cc.

References Cleanup(), Statistics::Print(), and stats.

Referenced by Idle(), and main().

00256 { 00257 printf("Machine halting!\n\n"); 00258 stats->Print(); 00259 Cleanup(); // Never returns. 00260 }

void Interrupt::Idle  ) 
 

Definition at line 225 of file interrupt.cc.

References DEBUG(), FALSE, Halt(), IdleMode, SystemMode, and TRUE.

Referenced by Thread::Suspend().

00226 { 00227 DEBUG('i', "Machine idling; checking for interrupts.\n"); 00228 status = IdleMode; 00229 if (CheckIfDue(TRUE)) 00230 { // check for any pending interrupts 00231 while (CheckIfDue(FALSE)) // check for any other pending 00232 ; // interrupts 00233 yieldOnReturn = FALSE; // since there's nothing in the 00234 // ready queue, the yield is automatic 00235 status = SystemMode; 00236 return; // return in case there's now 00237 // a runnable thread 00238 } 00239 00240 // if there are no pending interrupts, and nothing is on the ready 00241 // queue, it is time to stop. If the console or the network is 00242 // operating, there are *always* pending interrupts, so this code 00243 // is not reached. Instead, the halt must be invoked by the user program. 00244 00245 DEBUG('i', "Machine idle. No interrupts to do.\n"); 00246 printf("No threads ready or runnable, and no pending interrupts.\n"); 00247 printf("Assuming the program completed.\n"); 00248 Halt(); 00249 }

void Interrupt::OneTick  ) 
 

Definition at line 163 of file interrupt.cc.

References currentThread, DEBUG(), FALSE, IntOff, IntOn, MachineStatus, stats, SystemMode, SystemTick, Statistics::systemTicks, Statistics::totalTicks, UserTick, Statistics::userTicks, and Thread::Yield().

Referenced by Machine::Run(), and SetLevel().

00164 { 00165 MachineStatus old = status; 00166 00167 // advance simulated time 00168 if (status == SystemMode) 00169 { 00170 stats->totalTicks += SystemTick; 00171 stats->systemTicks += SystemTick; 00172 } 00173 else 00174 { // USER_PROGRAM 00175 stats->totalTicks += UserTick; 00176 stats->userTicks += UserTick; 00177 } 00178 DEBUG('i', "\n== Tick %d ==\n", stats->totalTicks); 00179 00180 // check any pending interrupts are now ready to fire 00181 ChangeLevel(IntOn, IntOff); // first, turn off interrupts 00182 // (interrupt handlers run with 00183 // interrupts disabled) 00184 while (CheckIfDue(FALSE)) // check for pending interrupts 00185 ; 00186 ChangeLevel(IntOff, IntOn); // re-enable interrupts 00187 if (yieldOnReturn) 00188 { // if the timer device handler asked 00189 // for a context switch, ok to do it now 00190 yieldOnReturn = FALSE; 00191 status = SystemMode; // yield is a kernel routine 00192 currentThread->Yield(); 00193 status = old; 00194 } 00195 }

void Interrupt::Schedule VoidFunctionPtr  handler,
int  arg,
int  when,
IntType  type
 

Definition at line 278 of file interrupt.cc.

References ASSERT, DEBUG(), List::SortedInsert(), stats, Statistics::totalTicks, and VoidFunctionPtr.

Referenced by Console::CheckCharAvail(), Network::CheckPktAvail(), Console::Console(), Network::Network(), Console::PutChar(), Disk::ReadRequest(), Network::Send(), Timer::Timer(), Timer::TimerExpired(), and Disk::WriteRequest().

00279 { 00280 int when = stats->totalTicks + fromNow; 00281 PendingInterrupt *toOccur = new PendingInterrupt(handler, arg, when, type); 00282 00283 DEBUG('i', "Scheduling interrupt handler the %s at time = %d\n", 00284 intTypeNames[type], when); 00285 ASSERT(fromNow > 0); 00286 00287 pending->SortedInsert(toOccur, when); 00288 }

IntStatus Interrupt::SetLevel IntStatus  level  ) 
 

Definition at line 119 of file interrupt.cc.

References ASSERT, FALSE, IntOff, IntOn, IntStatus, level, OneTick(), and timer_mask.

Referenced by Enable(), Thread::Finish(), Thread::Fork(), Semaphore::P(), Thread::Sleep(), Thread::UnSleep(), Semaphore::V(), and Thread::Yield().

00120 { 00121 IntStatus old = level; 00122 00123 ASSERT((now == IntOff) || (inHandler == FALSE));// interrupt handlers are 00124 // prohibited from enabling 00125 // interrupts 00126 00127 if (now == IntOff) 00128 { 00129 sigprocmask(SIG_BLOCK, &timer_mask, 0); 00130 } 00131 else 00132 { 00133 sigprocmask(SIG_UNBLOCK, &timer_mask, 0); 00134 } 00135 00136 00137 ChangeLevel(old, now); // change to new state 00138 if ((now == IntOn) && (old == IntOff)) 00139 OneTick(); // advance simulated time 00140 return old; 00141 }

void Interrupt::setStatus MachineStatus  st  )  [inline]
 

Definition at line 99 of file interrupt.h.

Referenced by Machine::RaiseException(), and Machine::Run().

00099 { status = st; }

void Interrupt::YieldOnReturn  ) 
 

Definition at line 208 of file interrupt.cc.

References TRUE.

Referenced by Scheduler::timerIntH().

00209 { 00210 //ASSERT(inHandler == TRUE); 00211 yieldOnReturn = TRUE; 00212 }


Member Data Documentation

IntStatus Interrupt::level
 

Definition at line 116 of file interrupt.h.

Referenced by DumpState(), Interrupt(), SetLevel(), and Scheduler::timerIntH().


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