AuroraRuntime/Source/Async/AuThreadState.hpp

84 lines
2.2 KiB
C++
Raw Permalink Normal View History

/***
Copyright (C) 2023 J Reece Wilson (a/k/a "Reece"). All rights reserved.
File: AuThreadState.hpp
Date: 2023-11-04
Author: Reece
***/
#pragma once
#include "AuThreadStateSingletons.hpp"
namespace Aurora::Async
{
struct AsyncLoop;
2023-11-11 11:27:01 +00:00
struct GroupState;
struct ThreadState;
struct ThreadStateShutdown
{
bool bBreakMainLoop {};
2023-11-11 11:27:01 +00:00
bool bDropSubmissions {};
bool bIsKillerThread {};
AuUInt32 uShutdownFence { 1 };
};
struct ThreadStateSync
{
ThreadStateSync();
AuConditionMutex cvWorkMutex;
AuConditionVariable cvVariable;
AuAUInt32 cvLSActive {};
AuAUInt32 cvHasWork {};
AuSPtr<AuLoop::ILSEvent> eventLs;
2024-01-23 22:35:18 +00:00
void SetEvent(bool bBoth = true, bool bHasWork = false);
bool Init();
void UpdateCVState(ThreadState *pState);
};
struct ThreadStateMeta
{
bool bOwnsThread {};
AuThreads::ThreadShared_t pThread;
2023-11-11 11:27:01 +00:00
WorkerId_t id;
};
struct ThreadStateStack
{
2024-09-05 16:38:54 +00:00
// Do not optimize away recursive self variables!
// Always evaluate!
// No multithread memory model awareness is required; we just need volatile.
volatile AuUInt32 uStackCookie {};
volatile AuUInt32 uStackMaxRecursiveAsyncPromiseCalls { 4 };
volatile AuUInt32 uStackCallDepth {};
volatile AuUInt32 uStackMaxCookie { 5 };
volatile AuUInt8 uWorkMultipopCount { 32 };
2023-11-11 11:27:01 +00:00
};
2023-11-11 11:27:01 +00:00
struct ThreadStateFeatureCallbacks
{
AuMutex mutex;
AuList<AuSPtr<AuThreads::IThreadFeature>> features;
};
struct ThreadStateBase
{
ThreadStateBase();
~ThreadStateBase();
2023-11-11 11:27:01 +00:00
AuWPtr<GroupState> parent;
/////////////////////////////////
ThreadStateShutdown shutdown;
ThreadStateMeta thread;
ThreadStateSync sync;
AuSPtr<AsyncLoop> asyncLoop;
ThreadStateStack stackState;
2023-11-11 11:27:01 +00:00
ThreadStateFeatureCallbacks tlsFeatures;
ThreadStateSingletons singletons;
bool Init();
void Deinit();
};
}