per-instance locking
All checks were successful
BlockStorage/repertory/pipeline/head This commit looks good
All checks were successful
BlockStorage/repertory/pipeline/head This commit looks good
This commit is contained in:
parent
d0f2f78698
commit
7605be809c
@ -23,6 +23,7 @@
|
|||||||
#define REPERTORY_INCLUDE_UI_HANDLERS_HPP_
|
#define REPERTORY_INCLUDE_UI_HANDLERS_HPP_
|
||||||
|
|
||||||
#include "events/consumers/console_consumer.hpp"
|
#include "events/consumers/console_consumer.hpp"
|
||||||
|
#include <unordered_map>
|
||||||
|
|
||||||
namespace repertory::ui {
|
namespace repertory::ui {
|
||||||
class mgmt_app_config;
|
class mgmt_app_config;
|
||||||
@ -48,11 +49,11 @@ private:
|
|||||||
private:
|
private:
|
||||||
console_consumer console;
|
console_consumer console;
|
||||||
mutable std::mutex mtx_;
|
mutable std::mutex mtx_;
|
||||||
|
mutable std::unordered_map<std::string, std::recursive_mutex> mtx_lookup_;
|
||||||
|
|
||||||
private:
|
private:
|
||||||
[[nodiscard]] static auto data_directory_exists(provider_type prov,
|
[[nodiscard]] auto data_directory_exists(provider_type prov,
|
||||||
std::string_view name)
|
std::string_view name) const -> bool;
|
||||||
-> bool;
|
|
||||||
|
|
||||||
void handle_get_mount(auto &&req, auto &&res) const;
|
void handle_get_mount(auto &&req, auto &&res) const;
|
||||||
|
|
||||||
|
@ -150,14 +150,23 @@ handlers::handlers(mgmt_app_config *config, httplib::Server *server)
|
|||||||
|
|
||||||
handlers::~handlers() { event_system::instance().stop(); }
|
handlers::~handlers() { event_system::instance().stop(); }
|
||||||
|
|
||||||
auto handlers::data_directory_exists(provider_type prov, std::string_view name)
|
auto handlers::data_directory_exists(provider_type prov,
|
||||||
-> bool {
|
std::string_view name) const -> bool {
|
||||||
auto data_dir = utils::path::combine(app_config::get_root_data_directory(),
|
auto data_dir = utils::path::combine(app_config::get_root_data_directory(),
|
||||||
{
|
{
|
||||||
app_config::get_provider_name(prov),
|
app_config::get_provider_name(prov),
|
||||||
name,
|
name,
|
||||||
});
|
});
|
||||||
return utils::file::directory{data_dir}.exists();
|
auto ret = utils::file::directory{data_dir}.exists();
|
||||||
|
if (ret) {
|
||||||
|
return ret;
|
||||||
|
}
|
||||||
|
|
||||||
|
unique_mutex_lock lock(mtx_);
|
||||||
|
mtx_lookup_.erase(
|
||||||
|
fmt::format("{}-{}", name, app_config::get_provider_name(prov)));
|
||||||
|
lock.unlock();
|
||||||
|
return ret;
|
||||||
}
|
}
|
||||||
|
|
||||||
void handlers::handle_get_mount(auto &&req, auto &&res) const {
|
void handlers::handle_get_mount(auto &&req, auto &&res) const {
|
||||||
@ -392,7 +401,12 @@ auto handlers::launch_process(provider_type prov, std::string_view name,
|
|||||||
|
|
||||||
auto cmd_line = fmt::format(R"({} {} {})", repertory_binary_, str_type, args);
|
auto cmd_line = fmt::format(R"({} {} {})", repertory_binary_, str_type, args);
|
||||||
|
|
||||||
mutex_lock lock(mtx_);
|
unique_mutex_lock lock(mtx_);
|
||||||
|
auto &inst_mtx = mtx_lookup_[fmt::format(
|
||||||
|
"{}-{}", name, app_config::get_provider_name(prov))];
|
||||||
|
lock.unlock();
|
||||||
|
|
||||||
|
recur_mutex_lock inst_lock(inst_mtx);
|
||||||
if (background) {
|
if (background) {
|
||||||
#if defined(_WIN32)
|
#if defined(_WIN32)
|
||||||
system(fmt::format(R"(start "" /b {})", cmd_line).c_str());
|
system(fmt::format(R"(start "" /b {})", cmd_line).c_str());
|
||||||
|
Loading…
x
Reference in New Issue
Block a user