2021-11-05 17:34:23 +00:00
|
|
|
/***
|
|
|
|
Copyright (C) 2021 J Reece Wilson (a/k/a "Reece"). All rights reserved.
|
|
|
|
|
|
|
|
File: ThreadState.hpp
|
|
|
|
Date: 2021-11-1
|
|
|
|
Author: Reece
|
|
|
|
***/
|
|
|
|
#pragma once
|
|
|
|
|
|
|
|
#include "AsyncRunnable.hpp"
|
|
|
|
|
|
|
|
namespace Aurora::Async
|
|
|
|
{
|
|
|
|
using WorkEntry_t = AuPair<ThreadId_t, AuSPtr<IAsyncRunnable>>;
|
|
|
|
|
|
|
|
// TODO: this is a hack because i havent implemented an epoll abstraction yet
|
|
|
|
struct AsyncAppWaitSourceRequest
|
|
|
|
{
|
2022-06-11 23:52:46 +00:00
|
|
|
AuConsumer<AuSPtr<AuLoop::ILoopSource>, bool> callback;
|
|
|
|
AuSPtr<AuLoop::ILoopSource> loopSource;
|
2021-11-05 17:34:23 +00:00
|
|
|
AuUInt32 requestedOffset;
|
|
|
|
AuUInt64 startTime;
|
|
|
|
AuUInt64 endTime;
|
|
|
|
};
|
|
|
|
|
|
|
|
struct GroupState;
|
2022-03-10 15:35:01 +00:00
|
|
|
struct AsyncLoop;
|
2021-11-05 17:34:23 +00:00
|
|
|
|
|
|
|
struct ThreadState
|
|
|
|
{
|
2023-05-25 00:55:55 +00:00
|
|
|
ThreadState() : running(true, false, true),
|
2023-06-07 19:35:31 +00:00
|
|
|
cvVariable(AuUnsafeRaiiToShared(cvWorkMutex.AsPointer())),
|
|
|
|
isDeadEvent(false, false, true)
|
2023-05-25 00:55:55 +00:00
|
|
|
{
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
// :vomit:
|
2021-11-05 17:34:23 +00:00
|
|
|
WorkerId_t id;
|
2023-05-25 00:55:55 +00:00
|
|
|
AuUInt8 multipopCount = 32;
|
2021-11-05 17:34:23 +00:00
|
|
|
AuUInt32 lastFrameTime {};
|
|
|
|
AuThreads::ThreadShared_t threadObject;
|
|
|
|
AuWPtr<GroupState> parent;
|
2023-05-25 00:55:55 +00:00
|
|
|
AuThreadPrimitives::Semaphore syncSema;
|
2023-06-07 19:35:31 +00:00
|
|
|
AuThreadPrimitives::Event isDeadEvent;
|
2021-11-05 17:34:23 +00:00
|
|
|
AuList<AuSPtr<AuThreads::IThreadFeature>> features;
|
|
|
|
bool rejecting {};
|
|
|
|
bool exiting {};
|
|
|
|
bool shuttingdown {};
|
2023-01-30 14:32:26 +00:00
|
|
|
bool exitingflag2 {};
|
2023-05-25 00:55:55 +00:00
|
|
|
AuThreadPrimitives::Event running;
|
2021-11-05 17:34:23 +00:00
|
|
|
//bool running;
|
|
|
|
AuList<AsyncAppWaitSourceRequest> loopSources;
|
|
|
|
AuList<WorkEntry_t> pendingWorkItems;
|
2022-03-10 15:35:01 +00:00
|
|
|
AuSPtr<AsyncLoop> asyncLoop;
|
|
|
|
Utility::RateLimiter rateLimiter;
|
|
|
|
ERunMode runMode;
|
2022-05-19 23:56:58 +00:00
|
|
|
int cookie {0};
|
2023-02-08 18:23:37 +00:00
|
|
|
bool bAlreadyDoingExitTick {};
|
|
|
|
bool bBreakEarly {};
|
|
|
|
bool bIsKiller {};
|
2023-01-30 14:32:26 +00:00
|
|
|
|
|
|
|
//
|
|
|
|
AuThreadPrimitives::SpinLock externalFencesLock;
|
|
|
|
AuList<AuThreading::IWaitable *> externalFences;
|
2023-05-25 00:55:55 +00:00
|
|
|
|
|
|
|
//
|
|
|
|
|
|
|
|
AuThreadPrimitives::ConditionMutex cvWorkMutex;
|
|
|
|
AuThreadPrimitives::ConditionVariable cvVariable;
|
|
|
|
AuSPtr<AuLoop::ILSEvent> eventLs;
|
|
|
|
AuSPtr<AuLoop::ILoopSource> asyncLoopSourceShared;
|
2021-11-05 17:34:23 +00:00
|
|
|
};
|
|
|
|
}
|