2 * Copyright 2014, Paweł Dziepak, pdziepak@quarnos.org.
3 * Distributed under the terms of the MIT License.
5 #ifndef KERNEL_SCHEDULER_LOCKING_H
6 #define KERNEL_SCHEDULER_LOCKING_H
9 #include <util/AutoLock.h>
11 #include "scheduler_cpu.h"
17 class CPURunQueueLocking
{
19 inline bool Lock(CPUEntry
* cpu
)
25 inline void Unlock(CPUEntry
* cpu
)
27 cpu
->UnlockRunQueue();
31 typedef AutoLocker
<CPUEntry
, CPURunQueueLocking
> CPURunQueueLocker
;
34 class CoreRunQueueLocking
{
36 inline bool Lock(CoreEntry
* core
)
42 inline void Unlock(CoreEntry
* core
)
44 core
->UnlockRunQueue();
48 typedef AutoLocker
<CoreEntry
, CoreRunQueueLocking
> CoreRunQueueLocker
;
50 class CoreCPUHeapLocking
{
52 inline bool Lock(CoreEntry
* core
)
58 inline void Unlock(CoreEntry
* core
)
60 core
->UnlockCPUHeap();
64 typedef AutoLocker
<CoreEntry
, CoreCPUHeapLocking
> CoreCPUHeapLocker
;
66 class SchedulerModeLocking
{
68 bool Lock(int* /* lockable */)
70 CPUEntry::GetCPU(smp_get_current_cpu())->EnterScheduler();
74 void Unlock(int* /* lockable */)
76 CPUEntry::GetCPU(smp_get_current_cpu())->ExitScheduler();
80 class SchedulerModeLocker
:
81 public AutoLocker
<int, SchedulerModeLocking
> {
83 SchedulerModeLocker(bool alreadyLocked
= false, bool lockIfNotLocked
= true)
85 AutoLocker
<int, SchedulerModeLocking
>(&fDummy
, alreadyLocked
,
94 class InterruptsSchedulerModeLocking
{
96 bool Lock(int* lockable
)
98 *lockable
= disable_interrupts();
99 CPUEntry::GetCPU(smp_get_current_cpu())->EnterScheduler();
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
> {
113 InterruptsSchedulerModeLocker(bool alreadyLocked
= false,
114 bool lockIfNotLocked
= true)
116 AutoLocker
<int, InterruptsSchedulerModeLocking
>(&fState
, alreadyLocked
,
125 class InterruptsBigSchedulerLocking
{
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();
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
> {
146 InterruptsBigSchedulerLocker()
148 AutoLocker
<int, InterruptsBigSchedulerLocking
>(&fState
, false, true)
157 } // namespace Scheduler
160 #endif // KERNEL_SCHEDULER_LOCKING_H