summaryrefslogtreecommitdiff
path: root/src/core/hle/kernel/kernel.cpp
diff options
context:
space:
mode:
Diffstat (limited to 'src/core/hle/kernel/kernel.cpp')
-rw-r--r--src/core/hle/kernel/kernel.cpp16
1 files changed, 16 insertions, 0 deletions
diff --git a/src/core/hle/kernel/kernel.cpp b/src/core/hle/kernel/kernel.cpp
index 600d6ec74..7a913520d 100644
--- a/src/core/hle/kernel/kernel.cpp
+++ b/src/core/hle/kernel/kernel.cpp
@@ -12,6 +12,7 @@
12 12
13#include "core/core.h" 13#include "core/core.h"
14#include "core/core_timing.h" 14#include "core/core_timing.h"
15#include "core/core_timing_util.h"
15#include "core/hle/kernel/address_arbiter.h" 16#include "core/hle/kernel/address_arbiter.h"
16#include "core/hle/kernel/client_port.h" 17#include "core/hle/kernel/client_port.h"
17#include "core/hle/kernel/handle_table.h" 18#include "core/hle/kernel/handle_table.h"
@@ -96,6 +97,7 @@ struct KernelCore::Impl {
96 97
97 InitializeSystemResourceLimit(kernel); 98 InitializeSystemResourceLimit(kernel);
98 InitializeThreads(); 99 InitializeThreads();
100 InitializePreemption();
99 } 101 }
100 102
101 void Shutdown() { 103 void Shutdown() {
@@ -111,6 +113,7 @@ struct KernelCore::Impl {
111 113
112 thread_wakeup_callback_handle_table.Clear(); 114 thread_wakeup_callback_handle_table.Clear();
113 thread_wakeup_event_type = nullptr; 115 thread_wakeup_event_type = nullptr;
116 preemption_event = nullptr;
114 117
115 named_ports.clear(); 118 named_ports.clear();
116 } 119 }
@@ -133,6 +136,18 @@ struct KernelCore::Impl {
133 system.CoreTiming().RegisterEvent("ThreadWakeupCallback", ThreadWakeupCallback); 136 system.CoreTiming().RegisterEvent("ThreadWakeupCallback", ThreadWakeupCallback);
134 } 137 }
135 138
139 void InitializePreemption() {
140 preemption_event = system.CoreTiming().RegisterEvent(
141 "PreemptionCallback", [this](u64 userdata, s64 cycles_late) {
142 global_scheduler.PreemptThreads();
143 s64 time_interval = Core::Timing::msToCycles(std::chrono::milliseconds(10));
144 system.CoreTiming().ScheduleEvent(time_interval, preemption_event);
145 });
146
147 s64 time_interval = Core::Timing::msToCycles(std::chrono::milliseconds(10));
148 system.CoreTiming().ScheduleEvent(time_interval, preemption_event);
149 }
150
136 std::atomic<u32> next_object_id{0}; 151 std::atomic<u32> next_object_id{0};
137 std::atomic<u64> next_kernel_process_id{Process::InitialKIPIDMin}; 152 std::atomic<u64> next_kernel_process_id{Process::InitialKIPIDMin};
138 std::atomic<u64> next_user_process_id{Process::ProcessIDMin}; 153 std::atomic<u64> next_user_process_id{Process::ProcessIDMin};
@@ -146,6 +161,7 @@ struct KernelCore::Impl {
146 SharedPtr<ResourceLimit> system_resource_limit; 161 SharedPtr<ResourceLimit> system_resource_limit;
147 162
148 Core::Timing::EventType* thread_wakeup_event_type = nullptr; 163 Core::Timing::EventType* thread_wakeup_event_type = nullptr;
164 Core::Timing::EventType* preemption_event = nullptr;
149 // TODO(yuriks): This can be removed if Thread objects are explicitly pooled in the future, 165 // TODO(yuriks): This can be removed if Thread objects are explicitly pooled in the future,
150 // allowing us to simply use a pool index or similar. 166 // allowing us to simply use a pool index or similar.
151 Kernel::HandleTable thread_wakeup_callback_handle_table; 167 Kernel::HandleTable thread_wakeup_callback_handle_table;