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