From e2d8316401427ab494cf507489d9885658f6769e Mon Sep 17 00:00:00 2001 From: TuxSH Date: Mon, 5 Nov 2018 23:16:35 +0100 Subject: [PATCH] Fix KCondition variable; add timeout parameter to ILimitableResource --- .../mesosphere/interfaces/ILimitedResource.hpp | 4 +++- mesosphere/include/mesosphere/threading/KThread.hpp | 2 +- mesosphere/source/kresources/KResourceLimit.cpp | 2 -- mesosphere/source/threading/KConditionVariable.cpp | 13 ++++++++----- 4 files changed, 12 insertions(+), 9 deletions(-) diff --git a/mesosphere/include/mesosphere/interfaces/ILimitedResource.hpp b/mesosphere/include/mesosphere/interfaces/ILimitedResource.hpp index 3d172454a..1f899694f 100644 --- a/mesosphere/include/mesosphere/interfaces/ILimitedResource.hpp +++ b/mesosphere/include/mesosphere/interfaces/ILimitedResource.hpp @@ -15,10 +15,12 @@ void ReleaseResource(const SharedPtr &reslimit, KAutoObject::Typ } -template +template class ILimitedResource { public: + static constexpr auto maxResourceAcqWaitTime = maxResourceAcqWaitTimeMsec * 1ms; + const SharedPtr& GetResourceOwner() const { return resourceOwner; } void SetResourceOwner(SharedPtr owner) { diff --git a/mesosphere/include/mesosphere/threading/KThread.hpp b/mesosphere/include/mesosphere/threading/KThread.hpp index 1a4b1a7e7..09c08be69 100644 --- a/mesosphere/include/mesosphere/threading/KThread.hpp +++ b/mesosphere/include/mesosphere/threading/KThread.hpp @@ -22,7 +22,7 @@ using ThreadMutexWaitListBaseHook = boost::intrusive::list_base_hook, + public ILimitedResource, public ISetAllocated, public IAlarmable, public ThreadWaitListBaseHook, diff --git a/mesosphere/source/kresources/KResourceLimit.cpp b/mesosphere/source/kresources/KResourceLimit.cpp index 2343a14f6..ed5f4f354 100644 --- a/mesosphere/source/kresources/KResourceLimit.cpp +++ b/mesosphere/source/kresources/KResourceLimit.cpp @@ -64,8 +64,6 @@ bool KResourceLimit::ReserveDetail(KResourceLimit::Category category, size_t cou }; if (timeoutTime <= KSystemClock::never) { - // TODO, check is actually < 0 - // TODO timeout ok = true; condvar.wait(condition); } else { diff --git a/mesosphere/source/threading/KConditionVariable.cpp b/mesosphere/source/threading/KConditionVariable.cpp index bdb669b78..bab058971 100644 --- a/mesosphere/source/threading/KConditionVariable.cpp +++ b/mesosphere/source/threading/KConditionVariable.cpp @@ -8,16 +8,19 @@ namespace mesosphere void KConditionVariable::wait_until_impl(const KSystemClock::time_point &timeoutPoint) noexcept { // Official kernel counts number of waiters, but that isn't necessary + bool hasWaited = false; + KThread *currentThread = KCoreContext::GetCurrentInstance().GetCurrentThread(); { - KThread *currentThread = KCoreContext::GetCurrentInstance().GetCurrentThread(); KScopedCriticalSection criticalSection{}; mutex_.unlock(); - if (currentThread->WaitForKernelSync(waiterList)) { - (void)timeoutPoint; //TODO! - } else { - // Termination + if (currentThread->WaitForKernelSync(waiterList) && timeoutPoint > KSystemClock::time_point{}) { + hasWaited = true; + currentThread->SetAlarmTime(timeoutPoint); } } + if (hasWaited) { + currentThread->ClearAlarm(); + } mutex_.lock(); }