1 // lib/kernel/time/timer.cc -- Generic timer multiplexing
3 // This software is copyright (c) 2006 Scott Wood <scott@buserror.net>.
5 // This software is provided 'as-is', without any express or implied warranty.
6 // In no event will the authors or contributors be held liable for any damages
7 // arising from the use of this software.
9 // Permission is hereby granted to everyone, free of charge, to use, copy,
10 // modify, prepare derivative works of, publish, distribute, perform,
11 // sublicense, and/or sell copies of the Software, provided that the above
12 // copyright notice and disclaimer of warranty be included in all copies or
13 // substantial portions of this software.
15 #include <kernel/time.h>
16 #include <lowlevel/clock.h>
19 void TimerMux::arm(TimerEntry *entry, Time expiry)
21 AutoSpinLockRecIRQ autolock(lock);
23 bool was_empty = heap.empty();
27 oldexpiry = heap.get_top()->expiry;
29 // Shut up the compiler
30 oldexpiry.seconds = 0;
34 entry->expiry = expiry;
36 if (entry->is_armed())
41 Time newexpiry = heap.get_top()->expiry;
42 if (was_empty || oldexpiry != newexpiry)
43 parent.arm(newexpiry);
46 void TimerMux::disarm(TimerEntry *entry)
48 AutoSpinLockRecIRQ autolock(lock);
50 if (entry->is_armed()) {
51 bool was_top = entry == heap.get_top();
56 parent.arm(heap.get_top()->expiry);
62 DroppableAutoSpinLockRecIRQ autolock(lock);
65 TimerEntry *top = heap.get_top();
69 if (now < top->expiry)
80 parent.arm(heap.get_top()->expiry);
83 void TimerEntry::set_action(System::Events::Event *event)
88 void TimerEntry::action()
94 #include _KERNEL_SERVER(time/timer/footer.cc)