Implement KCriticalSection (mostly)
This commit is contained in:
@@ -45,7 +45,7 @@ class KInterruptMaskGuard final {
|
||||
KInterruptMaskGuard &operator=(KInterruptMaskGuard &&) = delete;
|
||||
|
||||
private:
|
||||
FlagsType flags;
|
||||
FlagsType flags = 0;
|
||||
};
|
||||
|
||||
}
|
||||
|
||||
@@ -12,7 +12,7 @@ inline void IncrementThreadInterruptBottomHalfLockCount(KThread &thread);
|
||||
inline void DecrementThreadInterruptBottomHalfLockCount(KThread &thread);
|
||||
|
||||
template<bool disableInterrupts = false>
|
||||
class KInterruptSpinLock final : public KSpinLock {
|
||||
class KInterruptSpinLock : public KSpinLock {
|
||||
public:
|
||||
|
||||
bool try_lock()
|
||||
@@ -48,7 +48,7 @@ class KInterruptSpinLock final : public KSpinLock {
|
||||
};
|
||||
|
||||
template<>
|
||||
class KInterruptSpinLock<true> final : public KSpinLock {
|
||||
class KInterruptSpinLock<true> : public KSpinLock {
|
||||
public:
|
||||
|
||||
bool try_lock()
|
||||
@@ -80,7 +80,7 @@ class KInterruptSpinLock<true> final : public KSpinLock {
|
||||
KInterruptSpinLock &operator=(KInterruptSpinLock &&) = delete;
|
||||
|
||||
private:
|
||||
typename KInterruptMaskGuard::FlagsType flags;
|
||||
typename KInterruptMaskGuard::FlagsType flags = 0;
|
||||
};
|
||||
|
||||
}
|
||||
|
||||
26
mesosphere/include/mesosphere/threading/KCriticalSection.hpp
Normal file
26
mesosphere/include/mesosphere/threading/KCriticalSection.hpp
Normal file
@@ -0,0 +1,26 @@
|
||||
#pragma once
|
||||
|
||||
#include <mesosphere/interrupts/KInterruptSpinLock.hpp>
|
||||
|
||||
namespace mesosphere
|
||||
{
|
||||
|
||||
class KCriticalSection final : public KInterruptSpinLock<false> {
|
||||
public:
|
||||
|
||||
bool try_lock();
|
||||
void lock();
|
||||
void unlock();
|
||||
|
||||
KCriticalSection() = default;
|
||||
KCriticalSection(const KCriticalSection &) = delete;
|
||||
KCriticalSection(KCriticalSection &&) = delete;
|
||||
KCriticalSection &operator=(const KCriticalSection &) = delete;
|
||||
KCriticalSection &operator=(KCriticalSection &&) = delete;
|
||||
|
||||
private:
|
||||
KThread *lockingThread = nullptr;
|
||||
ulong lockCount = 0;
|
||||
};
|
||||
|
||||
}
|
||||
@@ -4,14 +4,12 @@
|
||||
#include <mutex>
|
||||
#include <mesosphere/core/util.hpp>
|
||||
#include <mesosphere/threading/KMultiLevelQueue.hpp>
|
||||
#include <mesosphere/threading/KCriticalSection.hpp>
|
||||
#include <mesosphere/threading/KThread.hpp>
|
||||
|
||||
namespace mesosphere
|
||||
{
|
||||
|
||||
//TODO
|
||||
struct KCriticalSection { void lock() {} void unlock() {} bool try_lock() {return true;} };
|
||||
|
||||
class KScheduler {
|
||||
public:
|
||||
class Global {
|
||||
@@ -40,6 +38,8 @@ class KScheduler {
|
||||
|
||||
static constexpr uint minRegularPriority = 2;
|
||||
private:
|
||||
friend class KScheduler;
|
||||
|
||||
static void TransferThreadToCore(KThread &thread, int coreId);
|
||||
static void AskForReselectionOrMarkRedundant(KThread *currentThread, KThread *winner);
|
||||
|
||||
@@ -91,6 +91,11 @@ class KScheduler {
|
||||
static void YieldCurrentThreadAndBalanceLoad();
|
||||
static void YieldCurrentThreadAndWaitForLoadBalancing();
|
||||
|
||||
static void HandleCriticalSectionLeave();
|
||||
friend void SchedulerHandleCriticalSectionLeave()
|
||||
{
|
||||
HandleCriticalSectionLeave();
|
||||
}
|
||||
|
||||
void ForceContextSwitch() {}
|
||||
void ForceContextSwitchAfterIrq() {}
|
||||
@@ -99,6 +104,7 @@ class KScheduler {
|
||||
|
||||
constexpr ulong GetIdleSelectionCount() const { return idleSelectionCount; }
|
||||
constexpr bool IsActive() const { return /*isActive */ true; } // TODO
|
||||
|
||||
private:
|
||||
bool hasContextSwitchStartedAfterIrq;
|
||||
bool isActive;
|
||||
@@ -128,11 +134,4 @@ class KScheduler {
|
||||
}
|
||||
};
|
||||
|
||||
// Convenience
|
||||
|
||||
class KScopedCriticalSection {
|
||||
private:
|
||||
std::scoped_lock<KCriticalSection> lk{KScheduler::GetCriticalSection()};
|
||||
};
|
||||
|
||||
}
|
||||
|
||||
@@ -0,0 +1,13 @@
|
||||
#pragma once
|
||||
|
||||
#include <mesosphere/threading/KScheduler.hpp>
|
||||
|
||||
namespace mesosphere
|
||||
{
|
||||
|
||||
class KScopedCriticalSection final {
|
||||
private:
|
||||
std::scoped_lock<KCriticalSection> lk{KScheduler::GetCriticalSection()};
|
||||
};
|
||||
|
||||
}
|
||||
Reference in New Issue
Block a user