2023-03-12 15:27:28 +00:00
|
|
|
/***
|
|
|
|
Copyright (C) 2023 J Reece Wilson (a/k/a "Reece"). All rights reserved.
|
|
|
|
|
|
|
|
File: AuWakeOnAddress.hpp
|
|
|
|
Date: 2023-3-10
|
|
|
|
Author: Reece
|
|
|
|
***/
|
|
|
|
#pragma once
|
|
|
|
|
|
|
|
#include "Primitives/AuConditionMutex.Generic.hpp"
|
|
|
|
#include "Primitives/AuConditionVariable.Generic.hpp"
|
|
|
|
|
2023-03-21 03:18:09 +00:00
|
|
|
namespace Aurora::Threading
|
2023-03-12 15:27:28 +00:00
|
|
|
{
|
2023-07-30 08:34:39 +00:00
|
|
|
static const auto kDefaultWaitPerProcess = 64;
|
2023-03-12 15:27:28 +00:00
|
|
|
|
|
|
|
struct WaitState;
|
|
|
|
|
|
|
|
struct WaitBuffer
|
|
|
|
{
|
|
|
|
char buffer[8];
|
|
|
|
AuUInt8 uSize;
|
|
|
|
|
|
|
|
static WaitBuffer From(const void *pBuf, AuUInt8 uSize);
|
|
|
|
bool Compare(const void *pBuf);
|
|
|
|
bool Compare(WaitState &state);
|
|
|
|
};
|
|
|
|
|
|
|
|
struct WaitState
|
|
|
|
{
|
|
|
|
WaitBuffer compare;
|
2023-06-15 19:44:27 +00:00
|
|
|
//AuOptionalEx<AuUInt64> qwNanoseconds;
|
|
|
|
AuOptionalEx<AuUInt64> qwNanosecondsAbs;
|
2023-03-12 15:27:28 +00:00
|
|
|
AuOptionalEx<AuUInt32> uDownsizeMask;
|
2023-03-13 23:57:32 +00:00
|
|
|
AuUInt32 uWordSize {};
|
2023-03-12 15:27:28 +00:00
|
|
|
};
|
|
|
|
|
|
|
|
struct WaitEntry
|
|
|
|
{
|
|
|
|
WaitEntry();
|
|
|
|
~WaitEntry();
|
|
|
|
|
2023-06-12 17:31:10 +00:00
|
|
|
WaitEntry *pNext {};
|
|
|
|
WaitEntry *pBefore {};
|
|
|
|
|
2023-03-12 15:27:28 +00:00
|
|
|
// synch
|
|
|
|
AuUInt32 uAtomic {}; // fastpath
|
2023-08-21 16:34:24 +00:00
|
|
|
Primitives::ConditionMutexInternal mutex; // mutex ctor must come before var
|
|
|
|
Primitives::ConditionVariableInternal variable; // ...and something all 2007+ micro and monolithic kernels should have to yield for an event
|
2023-03-12 15:27:28 +00:00
|
|
|
|
|
|
|
// state
|
|
|
|
const void *pAddress {};
|
|
|
|
AuUInt8 uSize {};
|
|
|
|
|
|
|
|
// bookkeeping (parent container)
|
|
|
|
bool bOverflow {};
|
2023-06-12 17:31:10 +00:00
|
|
|
bool bReleaseOnWake {};
|
2023-03-12 15:27:28 +00:00
|
|
|
|
|
|
|
bool TryAcquire(const void *pAddress, AuUInt8 uSize);
|
|
|
|
void Release();
|
|
|
|
|
|
|
|
bool SleepOn(WaitState &state);
|
|
|
|
bool TryWake(const void *pAddress);
|
|
|
|
bool TryWakeNoLock(const void *pAddress);
|
|
|
|
bool TryWakeNoLockNoReallyNoLock(const void *pAddress);
|
|
|
|
};
|
|
|
|
|
2023-06-12 17:31:10 +00:00
|
|
|
struct ProcessListWait
|
|
|
|
{
|
|
|
|
WaitEntry *pHead {};
|
|
|
|
WaitEntry *pTail {};
|
|
|
|
};
|
|
|
|
|
2023-07-30 08:34:39 +00:00
|
|
|
struct ProcessWaitNodeContainer
|
2023-03-12 15:27:28 +00:00
|
|
|
{
|
|
|
|
AuUInt32 uAtomic {};
|
2023-06-12 17:31:10 +00:00
|
|
|
#if defined(WOA_ENABLE_OLD_SHORT_LIST)
|
2023-03-12 15:27:28 +00:00
|
|
|
WaitEntry entries[kDefaultWaitPerProcess];
|
2023-06-12 17:31:10 +00:00
|
|
|
#endif
|
|
|
|
ProcessListWait waitList;
|
2023-03-12 15:27:28 +00:00
|
|
|
|
2023-08-19 19:37:24 +00:00
|
|
|
WaitEntry *WaitBufferFrom(const void *pAddress, AuUInt8 uSize);
|
2023-03-12 15:27:28 +00:00
|
|
|
|
2023-06-12 17:31:10 +00:00
|
|
|
template <typename T>
|
|
|
|
bool IterateWake(T callback);
|
|
|
|
|
2023-03-12 15:27:28 +00:00
|
|
|
void Lock();
|
|
|
|
|
|
|
|
void Unlock();
|
|
|
|
};
|
2023-07-30 08:34:39 +00:00
|
|
|
|
|
|
|
struct ProcessWaitContainer
|
|
|
|
{
|
|
|
|
ProcessWaitNodeContainer list[kDefaultWaitPerProcess];
|
|
|
|
|
2023-08-19 19:37:24 +00:00
|
|
|
WaitEntry *WaitBufferFrom(const void *pAddress, AuUInt8 uSize);
|
2023-07-30 08:34:39 +00:00
|
|
|
|
|
|
|
template <typename T>
|
2023-08-19 19:37:24 +00:00
|
|
|
bool IterateWake(const void *pAddress, T callback);
|
2023-07-30 08:34:39 +00:00
|
|
|
};
|
2023-03-12 15:27:28 +00:00
|
|
|
}
|