Files
salmanoff/hcore/include/componentThread.h
T
hayodea 870b8de249 Marionette: Introduce concept and add other 3 component threads
We introduce the 4 main component threads of execution for Harikoff:
* Marionette: This is the resident hijacking module that makes Harikoff
  instances non-persons, if configured to allow hijacking.
* Director: :)
* Canvas: :)
* Subconscious: DB, storage and recall.
2025-01-10 17:37:49 -04:00

62 lines
1.2 KiB
C++

#ifndef COMPONENT_THREAD_H
#define COMPONENT_THREAD_H
#include <thread>
#include <unordered_map>
#include <condition_variable>
#include <boost/asio.hpp>
#include <stdexcept>
namespace hk {
class ComponentThread
{
public:
ComponentThread()
: work(io_service), startupSync()
{}
boost::asio::io_service& getIoService(void) { return io_service; }
static boost::asio::io_service& getEventLoop(
std::thread::id id = std::this_thread::get_id())
{
auto it = componentThreads.find(id);
if (it == componentThreads.end())
{
throw std::runtime_error(std::string(__func__)
+ ": Thread ID not found in componentThreads map");
}
return it->second.getIoService();
}
public:
boost::asio::io_service io_service;
boost::asio::io_service::work work;
std::thread thread;
struct StartupSync {
std::mutex mutex;
std::condition_variable cv;
bool ready;
StartupSync() : ready(false) {}
} startupSync;
static std::unordered_map<std::thread::id, ComponentThread&> componentThreads;
};
namespace director {
extern ComponentThread director;
}
namespace simulator {
extern ComponentThread canvas;
}
namespace subconscious {
extern ComponentThread subconscious;
}
} // namespace hk
#endif // COMPONENT_THREAD_H