libroot/posix/stdio: Remove unused portions.
[haiku.git] / src / system / kernel / scheduler / scheduler_locking.h
blob8feffe60edd5fcb818fb44747ade1960cc7a41ba
1 /*
2 * Copyright 2014, Paweł Dziepak, pdziepak@quarnos.org.
3 * Distributed under the terms of the MIT License.
4 */
5 #ifndef KERNEL_SCHEDULER_LOCKING_H
6 #define KERNEL_SCHEDULER_LOCKING_H
9 #include <util/AutoLock.h>
11 #include "scheduler_cpu.h"
14 namespace Scheduler {
17 class CPURunQueueLocking {
18 public:
19 inline bool Lock(CPUEntry* cpu)
21 cpu->LockRunQueue();
22 return true;
25 inline void Unlock(CPUEntry* cpu)
27 cpu->UnlockRunQueue();
31 typedef AutoLocker<CPUEntry, CPURunQueueLocking> CPURunQueueLocker;
34 class CoreRunQueueLocking {
35 public:
36 inline bool Lock(CoreEntry* core)
38 core->LockRunQueue();
39 return true;
42 inline void Unlock(CoreEntry* core)
44 core->UnlockRunQueue();
48 typedef AutoLocker<CoreEntry, CoreRunQueueLocking> CoreRunQueueLocker;
50 class CoreCPUHeapLocking {
51 public:
52 inline bool Lock(CoreEntry* core)
54 core->LockCPUHeap();
55 return true;
58 inline void Unlock(CoreEntry* core)
60 core->UnlockCPUHeap();
64 typedef AutoLocker<CoreEntry, CoreCPUHeapLocking> CoreCPUHeapLocker;
66 class SchedulerModeLocking {
67 public:
68 bool Lock(int* /* lockable */)
70 CPUEntry::GetCPU(smp_get_current_cpu())->EnterScheduler();
71 return true;
74 void Unlock(int* /* lockable */)
76 CPUEntry::GetCPU(smp_get_current_cpu())->ExitScheduler();
80 class SchedulerModeLocker :
81 public AutoLocker<int, SchedulerModeLocking> {
82 public:
83 SchedulerModeLocker(bool alreadyLocked = false, bool lockIfNotLocked = true)
85 AutoLocker<int, SchedulerModeLocking>(&fDummy, alreadyLocked,
86 lockIfNotLocked)
90 private:
91 int fDummy;
94 class InterruptsSchedulerModeLocking {
95 public:
96 bool Lock(int* lockable)
98 *lockable = disable_interrupts();
99 CPUEntry::GetCPU(smp_get_current_cpu())->EnterScheduler();
100 return true;
103 void Unlock(int* lockable)
105 CPUEntry::GetCPU(smp_get_current_cpu())->ExitScheduler();
106 restore_interrupts(*lockable);
110 class InterruptsSchedulerModeLocker :
111 public AutoLocker<int, InterruptsSchedulerModeLocking> {
112 public:
113 InterruptsSchedulerModeLocker(bool alreadyLocked = false,
114 bool lockIfNotLocked = true)
116 AutoLocker<int, InterruptsSchedulerModeLocking>(&fState, alreadyLocked,
117 lockIfNotLocked)
121 private:
122 int fState;
125 class InterruptsBigSchedulerLocking {
126 public:
127 bool Lock(int* lockable)
129 *lockable = disable_interrupts();
130 for (int32 i = 0; i < smp_get_num_cpus(); i++)
131 CPUEntry::GetCPU(i)->LockScheduler();
132 return true;
135 void Unlock(int* lockable)
137 for (int32 i = 0; i < smp_get_num_cpus(); i++)
138 CPUEntry::GetCPU(i)->UnlockScheduler();
139 restore_interrupts(*lockable);
143 class InterruptsBigSchedulerLocker :
144 public AutoLocker<int, InterruptsBigSchedulerLocking> {
145 public:
146 InterruptsBigSchedulerLocker()
148 AutoLocker<int, InterruptsBigSchedulerLocking>(&fState, false, true)
152 private:
153 int fState;
157 } // namespace Scheduler
160 #endif // KERNEL_SCHEDULER_LOCKING_H