mirror of
https://github.com/latentPrion/libspinscale.git
synced 2026-06-23 19:48:32 +00:00
83 lines
2.8 KiB
C++
83 lines
2.8 KiB
C++
#ifndef PUPPET_APPLICATION_H
|
|
#define PUPPET_APPLICATION_H
|
|
|
|
#include <config.h>
|
|
#include <exception>
|
|
#include <functional>
|
|
#include <memory>
|
|
#include <string_view>
|
|
#include <vector>
|
|
|
|
#include <spinscale/co/group.h>
|
|
#include <spinscale/co/invokers.h>
|
|
#include <spinscale/componentThread.h>
|
|
|
|
namespace sscl {
|
|
|
|
class PuppetApplication
|
|
: public std::enable_shared_from_this<PuppetApplication>
|
|
{
|
|
public:
|
|
PuppetApplication(
|
|
const std::vector<std::shared_ptr<PuppetThread>> &threads);
|
|
~PuppetApplication() = default;
|
|
|
|
co::ViralNonPostingInvoker<void> joltAllPuppetThreadsCReq(
|
|
std::exception_ptr &exceptionPtr, std::function<void()> callback);
|
|
co::ViralNonPostingInvoker<void> startAllPuppetThreadsCReq(
|
|
std::exception_ptr &exceptionPtr, std::function<void()> callback);
|
|
co::ViralNonPostingInvoker<void> pauseAllPuppetThreadsCReq(
|
|
std::exception_ptr &exceptionPtr, std::function<void()> callback);
|
|
co::ViralNonPostingInvoker<void> resumeAllPuppetThreadsCReq(
|
|
std::exception_ptr &exceptionPtr, std::function<void()> callback);
|
|
co::ViralNonPostingInvoker<void> exitAllPuppetThreadsCReq(
|
|
std::exception_ptr &exceptionPtr, std::function<void()> callback);
|
|
|
|
// CPU distribution method
|
|
void distributeAndPinThreadsAcrossCpus();
|
|
|
|
protected:
|
|
using PuppetLifetimeMgmtInvoker =
|
|
PuppetThread::ViralThreadLifetimeMgmtInvoker;
|
|
using PuppetLifetimeMgmtGroup = co::Group<PuppetLifetimeMgmtInvoker>;
|
|
|
|
void addAllPuppetLifetimeInvokersToGroup(
|
|
PuppetLifetimeMgmtGroup &group,
|
|
std::vector<PuppetLifetimeMgmtInvoker> &invokers,
|
|
PuppetThread::ThreadOp threadOp) const;
|
|
|
|
std::vector<std::shared_ptr<PuppetThread>> componentThreads;
|
|
|
|
/**
|
|
* Indicates whether all puppet threads have been JOLTed at least once.
|
|
*
|
|
* JOLTing serves two critical purposes:
|
|
*
|
|
* 1. **Global Constructor Sequencing**: Since pthreads begin executing while
|
|
* global constructors are still being executed, globally defined pthreads
|
|
* cannot depend on global objects having been constructed. JOLTing is done
|
|
* by the CRT's main thread within main(), which provides a sequencing
|
|
* guarantee that global constructors have been called.
|
|
*
|
|
* 2. **shared_from_this Safety**: shared_from_this() requires a prior
|
|
* shared_ptr handle to be established. The global list of
|
|
* shared_ptr<ComponentThread> guarantees that at least one shared_ptr to
|
|
* each ComponentThread has been initialized before JOLTing occurs.
|
|
*
|
|
* This flag ensures that JOLTing happens exactly once and provides
|
|
* a synchronization point for the entire system initialization.
|
|
*/
|
|
bool threadsHaveBeenJolted = false;
|
|
|
|
private:
|
|
co::ViralNonPostingInvoker<void> allPuppetThreadsLifetimeOpCReq(
|
|
std::exception_ptr &exceptionPtr,
|
|
std::function<void()> callback,
|
|
PuppetThread::ThreadOp threadOp,
|
|
std::string_view emptyThreadsLogMessage);
|
|
};
|
|
|
|
} // namespace sscl
|
|
|
|
#endif // PUPPET_APPLICATION_H
|