summaryrefslogtreecommitdiffstats
path: root/src/core/hle/kernel/scheduler.h
diff options
context:
space:
mode:
authorbunnei <bunneidev@gmail.com>2020-02-23 04:32:21 +0100
committerGitHub <noreply@github.com>2020-02-23 04:32:21 +0100
commit3ef5f2017dba35742b32500e95744512dd5ef630 (patch)
treeca5359a2ae4e34608e5564e43bdefe4946e413c8 /src/core/hle/kernel/scheduler.h
parentMerge pull request #3444 from bunnei/linux-audio-fix (diff)
parentScheduler: Inline global scheduler in Scheduler Lock. (diff)
downloadyuzu-3ef5f2017dba35742b32500e95744512dd5ef630.tar
yuzu-3ef5f2017dba35742b32500e95744512dd5ef630.tar.gz
yuzu-3ef5f2017dba35742b32500e95744512dd5ef630.tar.bz2
yuzu-3ef5f2017dba35742b32500e95744512dd5ef630.tar.lz
yuzu-3ef5f2017dba35742b32500e95744512dd5ef630.tar.xz
yuzu-3ef5f2017dba35742b32500e95744512dd5ef630.tar.zst
yuzu-3ef5f2017dba35742b32500e95744512dd5ef630.zip
Diffstat (limited to 'src/core/hle/kernel/scheduler.h')
-rw-r--r--src/core/hle/kernel/scheduler.h46
1 files changed, 44 insertions, 2 deletions
diff --git a/src/core/hle/kernel/scheduler.h b/src/core/hle/kernel/scheduler.h
index 96db049cb..1c93a838c 100644
--- a/src/core/hle/kernel/scheduler.h
+++ b/src/core/hle/kernel/scheduler.h
@@ -6,6 +6,7 @@
#include <atomic>
#include <memory>
+#include <mutex>
#include <vector>
#include "common/common_types.h"
@@ -20,11 +21,13 @@ class System;
namespace Kernel {
+class KernelCore;
class Process;
+class SchedulerLock;
class GlobalScheduler final {
public:
- explicit GlobalScheduler(Core::System& system);
+ explicit GlobalScheduler(KernelCore& kernel);
~GlobalScheduler();
/// Adds a new thread to the scheduler
@@ -138,6 +141,14 @@ public:
void Shutdown();
private:
+ friend class SchedulerLock;
+
+ /// Lock the scheduler to the current thread.
+ void Lock();
+
+ /// Unlocks the scheduler, reselects threads, interrupts cores for rescheduling
+ /// and reschedules current core if needed.
+ void Unlock();
/**
* Transfers a thread into an specific core. If the destination_core is -1
* it will be unscheduled from its source code and added into its suggested
@@ -158,9 +169,14 @@ private:
// ordered from Core 0 to Core 3.
std::array<u32, Core::Hardware::NUM_CPU_CORES> preemption_priorities = {59, 59, 59, 62};
+ /// Scheduler lock mechanisms.
+ std::mutex inner_lock{}; // TODO(Blinkhawk): Replace for a SpinLock
+ std::atomic<s64> scope_lock{};
+ Core::EmuThreadHandle current_owner{Core::EmuThreadHandle::InvalidHandle()};
+
/// Lists all thread ids that aren't deleted/etc.
std::vector<std::shared_ptr<Thread>> thread_list;
- Core::System& system;
+ KernelCore& kernel;
};
class Scheduler final {
@@ -227,4 +243,30 @@ private:
bool is_context_switch_pending = false;
};
+class SchedulerLock {
+public:
+ explicit SchedulerLock(KernelCore& kernel);
+ ~SchedulerLock();
+
+protected:
+ KernelCore& kernel;
+};
+
+class SchedulerLockAndSleep : public SchedulerLock {
+public:
+ explicit SchedulerLockAndSleep(KernelCore& kernel, Handle& event_handle, Thread* time_task,
+ s64 nanoseconds);
+ ~SchedulerLockAndSleep();
+
+ void CancelSleep() {
+ sleep_cancelled = true;
+ }
+
+private:
+ Handle& event_handle;
+ Thread* time_task;
+ s64 nanoseconds;
+ bool sleep_cancelled{};
+};
+
} // namespace Kernel