00001 // alarm.h 00002 // Data structures for a software alarm clock. 00003 // 00004 // We make use of a hardware timer device, that generates 00005 // an interrupt every X time ticks (on real systems, X is 00006 // usually between 0.25 - 10 milliseconds). 00007 // 00008 // From this, we provide the ability for a thread to be 00009 // woken up after a delay; we also provide time-slicing. 00010 // 00011 // NOTE: this abstraction is not completely implemented. 00012 // 00013 // Copyright (c) 1992-1996 The Regents of the University of California. 00014 // All rights reserved. See copyright.h for copyright notice and limitation 00015 // of liability and disclaimer of warranty provisions. 00016 00017 #ifndef ALARM_H 00018 #define ALARM_H 00019 00020 #include "copyright.h" 00021 #include "utility.h" 00022 #include "callback.h" 00023 #include "timer.h" 00024 00025 // The following class defines a software alarm clock. 00026 class Alarm : public CallBackObj { 00027 public: 00028 Alarm(bool doRandomYield); // Initialize the timer, and callback 00029 // to "toCall" every time slice. 00030 ~Alarm() { delete timer; } 00031 00032 void WaitUntil(int x); // suspend execution until time > now + x 00033 // this method is not yet implemented 00034 00035 private: 00036 Timer *timer; // the hardware timer device 00037 00038 void CallBack(); // called when the hardware 00039 // timer generates an interrupt 00040 }; 00041 00042 #endif // ALARM_H