Rename hcore=>smocore
This commit is contained in:
@@ -0,0 +1,69 @@
|
||||
#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(),
|
||||
thread(ComponentThread::main, std::ref(*this))
|
||||
{}
|
||||
|
||||
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();
|
||||
}
|
||||
|
||||
static void main(ComponentThread &self);
|
||||
static void signalThread(std::thread::id id);
|
||||
static void validateThreadIds(void);
|
||||
|
||||
public:
|
||||
boost::asio::io_service io_service;
|
||||
boost::asio::io_service::work work;
|
||||
struct StartupSync {
|
||||
std::mutex mutex;
|
||||
std::condition_variable cv;
|
||||
bool ready;
|
||||
|
||||
StartupSync() : ready(false) {}
|
||||
} startupSync;
|
||||
|
||||
/* Always ensure that this is last so that the thread is spawned after
|
||||
* everything else.
|
||||
*/
|
||||
std::thread thread;
|
||||
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
|
||||
Reference in New Issue
Block a user