mirror of
https://github.com/ciphervance/supercell-wx.git
synced 2025-10-30 16:40:05 +00:00
Add async code to marker_manager
This commit is contained in:
parent
ad10e019fe
commit
57625b9680
1 changed files with 24 additions and 13 deletions
|
|
@ -10,6 +10,8 @@
|
||||||
|
|
||||||
#include <QStandardPaths>
|
#include <QStandardPaths>
|
||||||
#include <boost/json.hpp>
|
#include <boost/json.hpp>
|
||||||
|
#include <boost/asio/post.hpp>
|
||||||
|
#include <boost/asio/thread_pool.hpp>
|
||||||
|
|
||||||
namespace scwx
|
namespace scwx
|
||||||
{
|
{
|
||||||
|
|
@ -31,13 +33,15 @@ public:
|
||||||
class MarkerRecord;
|
class MarkerRecord;
|
||||||
|
|
||||||
explicit Impl(MarkerManager* self) : self_ {self} {}
|
explicit Impl(MarkerManager* self) : self_ {self} {}
|
||||||
~Impl() {}
|
~Impl() { threadPool_.join(); }
|
||||||
|
|
||||||
std::string markerSettingsPath_ {};
|
std::string markerSettingsPath_ {};
|
||||||
std::vector<std::shared_ptr<MarkerRecord>> markerRecords_ {};
|
std::vector<std::shared_ptr<MarkerRecord>> markerRecords_ {};
|
||||||
|
|
||||||
MarkerManager* self_;
|
MarkerManager* self_;
|
||||||
|
|
||||||
|
boost::asio::thread_pool threadPool_ {1u};
|
||||||
|
|
||||||
void InitializeMarkerSettings();
|
void InitializeMarkerSettings();
|
||||||
void ReadMarkerSettings();
|
void ReadMarkerSettings();
|
||||||
void WriteMarkerSettings();
|
void WriteMarkerSettings();
|
||||||
|
|
@ -166,19 +170,23 @@ MarkerManager::Impl::GetMarkerByName(const std::string& name)
|
||||||
|
|
||||||
MarkerManager::MarkerManager() : p(std::make_unique<Impl>(this))
|
MarkerManager::MarkerManager() : p(std::make_unique<Impl>(this))
|
||||||
{
|
{
|
||||||
// TODO THREADING?
|
|
||||||
|
boost::asio::post(p->threadPool_,
|
||||||
|
[this]()
|
||||||
|
{
|
||||||
try
|
try
|
||||||
{
|
{
|
||||||
p->InitializeMarkerSettings();
|
p->InitializeMarkerSettings();
|
||||||
|
|
||||||
// Read Marker settings on startup
|
// Read Marker settings on startup
|
||||||
// main::Application::WaitForInitialization();
|
main::Application::WaitForInitialization();
|
||||||
p->ReadMarkerSettings();
|
p->ReadMarkerSettings();
|
||||||
}
|
}
|
||||||
catch (const std::exception& ex)
|
catch (const std::exception& ex)
|
||||||
{
|
{
|
||||||
logger_->error(ex.what());
|
logger_->error(ex.what());
|
||||||
}
|
}
|
||||||
|
});
|
||||||
}
|
}
|
||||||
|
|
||||||
MarkerManager::~MarkerManager()
|
MarkerManager::~MarkerManager()
|
||||||
|
|
@ -264,6 +272,9 @@ void MarkerManager::move_marker(size_t from, size_t to)
|
||||||
std::shared_ptr<MarkerManager> MarkerManager::Instance()
|
std::shared_ptr<MarkerManager> MarkerManager::Instance()
|
||||||
{
|
{
|
||||||
static std::weak_ptr<MarkerManager> markerManagerReference_ {};
|
static std::weak_ptr<MarkerManager> markerManagerReference_ {};
|
||||||
|
static std::mutex instanceMutex_ {};
|
||||||
|
|
||||||
|
std::unique_lock lock(instanceMutex_);
|
||||||
|
|
||||||
std::shared_ptr<MarkerManager> markerManager =
|
std::shared_ptr<MarkerManager> markerManager =
|
||||||
markerManagerReference_.lock();
|
markerManagerReference_.lock();
|
||||||
|
|
|
||||||
Loading…
Add table
Add a link
Reference in a new issue