mirror of https://git.suyu.dev/suyu/suyu
kernel: time_manager: Protect access with a mutex.
This commit is contained in:
parent
24cae76d16
commit
b7ef581c6e
|
@ -32,6 +32,7 @@ TimeManager::TimeManager(Core::System& system_) : system{system_} {
|
||||||
}
|
}
|
||||||
|
|
||||||
void TimeManager::ScheduleTimeEvent(Handle& event_handle, Thread* timetask, s64 nanoseconds) {
|
void TimeManager::ScheduleTimeEvent(Handle& event_handle, Thread* timetask, s64 nanoseconds) {
|
||||||
|
std::lock_guard lock{mutex};
|
||||||
event_handle = timetask->GetGlobalHandle();
|
event_handle = timetask->GetGlobalHandle();
|
||||||
if (nanoseconds > 0) {
|
if (nanoseconds > 0) {
|
||||||
ASSERT(timetask);
|
ASSERT(timetask);
|
||||||
|
@ -46,6 +47,7 @@ void TimeManager::ScheduleTimeEvent(Handle& event_handle, Thread* timetask, s64
|
||||||
}
|
}
|
||||||
|
|
||||||
void TimeManager::UnscheduleTimeEvent(Handle event_handle) {
|
void TimeManager::UnscheduleTimeEvent(Handle event_handle) {
|
||||||
|
std::lock_guard lock{mutex};
|
||||||
if (event_handle == InvalidHandle) {
|
if (event_handle == InvalidHandle) {
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
@ -54,7 +56,7 @@ void TimeManager::UnscheduleTimeEvent(Handle event_handle) {
|
||||||
}
|
}
|
||||||
|
|
||||||
void TimeManager::CancelTimeEvent(Thread* time_task) {
|
void TimeManager::CancelTimeEvent(Thread* time_task) {
|
||||||
Handle event_handle = time_task->GetGlobalHandle();
|
const Handle event_handle = time_task->GetGlobalHandle();
|
||||||
UnscheduleTimeEvent(event_handle);
|
UnscheduleTimeEvent(event_handle);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -5,6 +5,7 @@
|
||||||
#pragma once
|
#pragma once
|
||||||
|
|
||||||
#include <memory>
|
#include <memory>
|
||||||
|
#include <mutex>
|
||||||
#include <unordered_map>
|
#include <unordered_map>
|
||||||
|
|
||||||
#include "core/hle/kernel/object.h"
|
#include "core/hle/kernel/object.h"
|
||||||
|
@ -42,6 +43,7 @@ private:
|
||||||
Core::System& system;
|
Core::System& system;
|
||||||
std::shared_ptr<Core::Timing::EventType> time_manager_event_type;
|
std::shared_ptr<Core::Timing::EventType> time_manager_event_type;
|
||||||
std::unordered_map<Handle, bool> cancelled_events;
|
std::unordered_map<Handle, bool> cancelled_events;
|
||||||
|
std::mutex mutex;
|
||||||
};
|
};
|
||||||
|
|
||||||
} // namespace Kernel
|
} // namespace Kernel
|
||||||
|
|
Loading…
Reference in New Issue