00001 #ifndef SCHEDULER_DISABLER_H_
00002 #define SCHEDULER_DISABLER_H_
00003
00004 #include <system/config.h>
00005 #include <cpu.h>
00006 #include <mmu.h>
00007 #include <compile_assert.h>
00008
00009 __BEGIN_SYS
00010
00011 template<bool b>
00012 struct SchedulerDisablerAssert {
00013 COMPILE_ASSERT(Traits<Thread>::active_scheduler == b);
00014 };
00015
00016 template<bool b> struct SchedulerDisabler : public SchedulerDisablerAssert<b> {
00017 inline SchedulerDisabler() : stop(true) {}
00018
00019 int stop;
00020 };
00021
00022 template<>
00023 struct SchedulerDisabler<true> : public SchedulerDisablerAssert<true> {
00024 inline SchedulerDisabler() : stop(true) {
00025 CPU::int_disable();
00026
00027 }
00028
00029 inline ~SchedulerDisabler() {
00030
00031 CPU::int_enable();
00032 }
00033
00034 int stop;
00035 };
00036
00037 #define IMP_DISABLE_SCHED(A) for (SchedulerDisabler<Traits<Thread>::active_scheduler> (A) = SchedulerDisabler<Traits<Thread>::active_scheduler>(); (A).stop == true; (A).stop = false)
00038 #define DISABLE_SCHED IMP_DISABLE_SCHED(CONCAT(__sched__, __LINE__))
00039
00040 __END_SYS
00041
00042 #endif