50 lines
1.4 KiB
C++
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;
|
|
}
|
|
} |