AuroraRuntime/Source/Threading/AuStopTheWorld.cpp
Jamie Reece Wilson 0571aa8dd4 [+] AU_LOCK_GLOBAL_GUARD
[+] AuThreading::GetShutdownReadLock()
2024-09-09 03:46:38 +01:00

50 lines
1.4 KiB
C++

/***
Copyright (C) Jamie Reece Wilson (a/k/a "Reece"). All rights reserved.
File: AuStopTheWorld.cpp
Date: 2024-09-09
Author: Reece
***/
#include <Source/RuntimeInternal.hpp>
#include "AuStopTheWorld.hpp"
#include "AuWakeOnAddress.hpp"
#include "Primitives/SMTYield.hpp"
namespace Aurora::Threading
{
static AuThreadPrimitives::RWLock gHolderRWLock;
AUKN_SYM IWaitable *GetShutdownReadLock()
{
return gHolderRWLock->AsReadable();
}
void WakeOnAddressHoldContainersAndTheWorld(const AuVoidFunc &func)
{
// We * must * allow ::GetShutdownLock() to be recursive, no matter how the runtime is configured
Primitives::ThrdCfg::gEnableRWLockWriteBiasOnReadLock = false;
{
// First: no-one shall pass anymore
AU_LOCK_GUARD(gHolderRWLock->AsWritable());
// Second: wait for any sleep ops to finish
for (AU_ITERATE_N(i, kDefaultWaitPerProcess))
{
gProcessWaitables.list[i].Lock();
}
{
func();
}
// Finally: reset
for (AU_ITERATE_N(i, kDefaultWaitPerProcess))
{
gProcessWaitables.list[i].Unlock();
}
}
Primitives::ThrdCfg::gEnableRWLockWriteBiasOnReadLock = gRuntimeConfig.threadingConfig.bEnableRWLockWriteBiasOnReadLock;
}
}