mirror of
https://github.com/Atmosphere-NX/Atmosphere.git
synced 2025-02-10 10:45:16 +00:00
Fix KCondition variable; add timeout parameter to ILimitableResource
This commit is contained in:
parent
0a0c05481e
commit
e2d8316401
4 changed files with 12 additions and 9 deletions
|
@ -15,10 +15,12 @@ void ReleaseResource(const SharedPtr<KResourceLimit> &reslimit, KAutoObject::Typ
|
|||
|
||||
}
|
||||
|
||||
template<typename Derived>
|
||||
template<typename Derived, uint maxResourceAcqWaitTimeMsec = 1000u>
|
||||
class ILimitedResource {
|
||||
public:
|
||||
|
||||
static constexpr auto maxResourceAcqWaitTime = maxResourceAcqWaitTimeMsec * 1ms;
|
||||
|
||||
const SharedPtr<KProcess>& GetResourceOwner() const { return resourceOwner; }
|
||||
void SetResourceOwner(SharedPtr<KProcess> owner)
|
||||
{
|
||||
|
|
|
@ -22,7 +22,7 @@ using ThreadMutexWaitListBaseHook = boost::intrusive::list_base_hook<boost::int
|
|||
|
||||
class KThread final :
|
||||
public KAutoObject,
|
||||
public ILimitedResource<KThread>,
|
||||
public ILimitedResource<KThread, 100u>,
|
||||
public ISetAllocated<KThread>,
|
||||
public IAlarmable,
|
||||
public ThreadWaitListBaseHook,
|
||||
|
|
|
@ -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 {
|
||||
|
|
|
@ -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();
|
||||
}
|
||||
|
||||
|
|
Loading…
Add table
Reference in a new issue