From 4dae7a1a1475b1e8b893133a7465d8b3e762f899 Mon Sep 17 00:00:00 2001 From: "Deomid \"rojer\" Ryabkov" Date: Sat, 13 Feb 2021 23:10:28 +0300 Subject: [PATCH] ubuntu: Make sure GPIO map doesn't get destroyed on exit --- platforms/ubuntu/src/ubuntu_gpio.cpp | 11 +++++++---- 1 file changed, 7 insertions(+), 4 deletions(-) diff --git a/platforms/ubuntu/src/ubuntu_gpio.cpp b/platforms/ubuntu/src/ubuntu_gpio.cpp index 3e3f08e42..516abf90f 100644 --- a/platforms/ubuntu/src/ubuntu_gpio.cpp +++ b/platforms/ubuntu/src/ubuntu_gpio.cpp @@ -44,11 +44,14 @@ struct GPIOPinCtx { } }; -static std::map> pins_; +static std::map> *pins_ = nullptr; static GPIOPinCtx *GetPinCtx(int pin) { - auto it = pins_.find(pin); - if (it == pins_.end()) return nullptr; + if (pins_ == nullptr) { + pins_ = new std::map>(); + } + auto it = pins_->find(pin); + if (it == pins_->end()) return nullptr; return it->second.get(); } @@ -60,7 +63,7 @@ static GPIOPinCtx *GetOrCreatePinCtx(int pin, enum mgos_gpio_mode mode) { LOG(LL_INFO, ("GPIO: New pin %s, mode %d (%s)", mgos_gpio_str(pin, buf), mode, (mode == MGOS_GPIO_MODE_INPUT ? "input" : "output"))); ctx = new_ctx.get(); - pins_.emplace(pin, std::move(new_ctx)); + pins_->emplace(pin, std::move(new_ctx)); } return ctx; }