From d12054ecd130a773c3a3f5f7bab5f20d87e2608a Mon Sep 17 00:00:00 2001 From: bWF0dGhpYXMK <127229721+bWF0dGhpYXMK@users.noreply.github.com> Date: Wed, 14 Feb 2024 11:16:36 +0100 Subject: [PATCH] =?UTF-8?q?Support=20of=20mutex=20inside=20get/set=20of=20?= =?UTF-8?q?configuration,=20which=20can=20be=20happen=E2=80=A6=20(#281)?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit * Support of mutex inside get/set of configuration, which can be happen, when getConfiguration is called from outside, during a changeconfiguration processing * Usage of recursive mutex, to avoid blocking in nested calls of the same thread --------- Signed-off-by: Matthias Suess Co-authored-by: Matthias Suess --- include/ocpp/v16/charge_point_configuration.hpp | 1 + lib/ocpp/v16/charge_point_configuration.cpp | 6 ++++-- 2 files changed, 5 insertions(+), 2 deletions(-) diff --git a/include/ocpp/v16/charge_point_configuration.hpp b/include/ocpp/v16/charge_point_configuration.hpp index af2a13cfa..65b1ac2a0 100644 --- a/include/ocpp/v16/charge_point_configuration.hpp +++ b/include/ocpp/v16/charge_point_configuration.hpp @@ -25,6 +25,7 @@ class ChargePointConfiguration { std::map> supported_message_types_from_central_system; std::set supported_message_types_sending; std::set supported_message_types_receiving; + std::recursive_mutex configuration_mutex; std::vector csv_to_measurand_with_phase_vector(std::string csv); bool validate_measurands(const json& config); diff --git a/lib/ocpp/v16/charge_point_configuration.cpp b/lib/ocpp/v16/charge_point_configuration.cpp index 424508cc1..462c18545 100644 --- a/lib/ocpp/v16/charge_point_configuration.cpp +++ b/lib/ocpp/v16/charge_point_configuration.cpp @@ -2074,6 +2074,7 @@ KeyValue ChargePointConfiguration::getWaitForStopTransactionsOnResetTimeoutKeyVa } std::optional ChargePointConfiguration::getCustomKeyValue(CiString<50> key) { + std::lock_guard lock(configuration_mutex); if (!this->config["Custom"].contains(key.get())) { return std::nullopt; } @@ -2098,7 +2099,7 @@ ConfigurationStatus ChargePointConfiguration::setCustomKey(CiString<50> key, CiS if (!kv.has_value() or (kv.value().readonly and !force)) { return ConfigurationStatus::Rejected; } - + std::lock_guard lock(configuration_mutex); try { const auto type = this->custom_schema["properties"][key]["type"]; if (type == "integer") { @@ -2122,7 +2123,7 @@ ConfigurationStatus ChargePointConfiguration::setCustomKey(CiString<50> key, CiS } std::optional ChargePointConfiguration::get(CiString<50> key) { - + std::lock_guard lock(configuration_mutex); // Internal Profile if (key == "ChargePointId") { return this->getChargePointIdKeyValue(); @@ -2421,6 +2422,7 @@ std::vector ChargePointConfiguration::get_all_key_value() { } ConfigurationStatus ChargePointConfiguration::set(CiString<50> key, CiString<500> value) { + std::lock_guard lock(configuration_mutex); if (key == "AllowOfflineTxForUnknownId") { if (this->getAllowOfflineTxForUnknownId() == std::nullopt) { return ConfigurationStatus::NotSupported;