From 600afa5f0f8b8d087c2172ebb0fd5aeff809f241 Mon Sep 17 00:00:00 2001 From: Michael Scire Date: Mon, 5 Nov 2018 03:47:15 -0800 Subject: [PATCH] mesosphere: Add convenience KScopedCriticalSection --- mesosphere/include/mesosphere/threading/KScheduler.hpp | 8 ++++++++ mesosphere/source/core/KSynchronizationObject.cpp | 4 ++-- mesosphere/source/threading/KMutex.cpp | 2 +- mesosphere/source/threading/KThread.cpp | 10 +++++----- 4 files changed, 16 insertions(+), 8 deletions(-) diff --git a/mesosphere/include/mesosphere/threading/KScheduler.hpp b/mesosphere/include/mesosphere/threading/KScheduler.hpp index c6ad2fa14..7c4180f60 100644 --- a/mesosphere/include/mesosphere/threading/KScheduler.hpp +++ b/mesosphere/include/mesosphere/threading/KScheduler.hpp @@ -1,6 +1,7 @@ #pragma once #include +#include #include #include #include @@ -127,4 +128,11 @@ class KScheduler { } }; +// Convenience + +class KScopedCriticalSection { + private: + std::scoped_lock lk{KScheduler::GetCriticalSection()}; +}; + } diff --git a/mesosphere/source/core/KSynchronizationObject.cpp b/mesosphere/source/core/KSynchronizationObject.cpp index c42ff4f83..a058caab4 100644 --- a/mesosphere/source/core/KSynchronizationObject.cpp +++ b/mesosphere/source/core/KSynchronizationObject.cpp @@ -13,9 +13,9 @@ KSynchronizationObject::~KSynchronizationObject() { } -void KSynchronizationObject::Signal() +void KSynchronizationObject::NotifyWaiters() { - std::lock_guard criticalSection{KScheduler::GetCriticalSection()}; + KScopedCriticalSection critical_section; if (IsSignaled()) { for (auto &&waiter : waiters) { diff --git a/mesosphere/source/threading/KMutex.cpp b/mesosphere/source/threading/KMutex.cpp index caaceb316..f734ac793 100644 --- a/mesosphere/source/threading/KMutex.cpp +++ b/mesosphere/source/threading/KMutex.cpp @@ -36,7 +36,7 @@ void KMutex::lock_slow_path(KThread &owner, KThread &requester) void KMutex::unlock_slow_path(KThread &owner) { - std::lock_guard criticalSection{KScheduler::GetCriticalSection()}; + KScopedCriticalSection critical_section; size_t count; KThread *newOwner = owner.RelinquishMutex(&count, (uiptr)this); native_handle_type newTag; diff --git a/mesosphere/source/threading/KThread.cpp b/mesosphere/source/threading/KThread.cpp index 18f98cf01..5811dd995 100644 --- a/mesosphere/source/threading/KThread.cpp +++ b/mesosphere/source/threading/KThread.cpp @@ -46,7 +46,7 @@ void KThread::RescheduleIfStatusEquals(SchedulingStatus expectedStatus, Scheduli void KThread::AddForcePauseReason(KThread::ForcePauseReason reason) { - std::lock_guard criticalSection{KScheduler::GetCriticalSection()}; + KScopedCriticalSection critical_section; if (!IsDying()) { AddForcePauseReasonToField(reason); @@ -58,7 +58,7 @@ void KThread::AddForcePauseReason(KThread::ForcePauseReason reason) void KThread::RemoveForcePauseReason(KThread::ForcePauseReason reason) { - std::lock_guard criticalSection{KScheduler::GetCriticalSection()}; + KScopedCriticalSection critical_section; if (!IsDying()) { RemoveForcePauseReasonToField(reason); @@ -104,7 +104,7 @@ void KThread::ResumeAllFromKernelSync(KThread::WaitList &waitList) void KThread::CancelKernelSync() { - std::lock_guard criticalSection{KScheduler::GetCriticalSection()}; + KScopedCriticalSection critical_section; if (GetSchedulingStatus() == SchedulingStatus::Paused) { // Note: transparent to force-pause if (currentWaitList != nullptr) { @@ -136,7 +136,7 @@ Result KThread::WaitSynchronizationImpl(int &outId, KSynchronizationObject **syn outId = -1; { - std::lock_guard criticalSection{KScheduler::GetCriticalSection()}; + KScopedCriticalSection critical_section; // Try to find an already signaled object. if (numSyncObjs >= 1) { @@ -178,7 +178,7 @@ Result KThread::WaitSynchronizationImpl(int &outId, KSynchronizationObject **syn // Now waiting... { - std::lock_guard criticalSection{KScheduler::GetCriticalSection()}; + KScopedCriticalSection critical_section; isWaitingSync = false; if (timeoutTime > KSystemClock::time_point{}) {