From cddf2994081f0ee6c3b9aad6bdd019d71a4ec5b5 Mon Sep 17 00:00:00 2001 From: Vladimir Byko-Ianko Date: Thu, 29 Oct 2020 13:27:58 +0300 Subject: [PATCH] [base] Optional lock guard. --- base/CMakeLists.txt | 1 + base/optional_lock_guard.hpp | 21 +++++++++++++++++++++ 2 files changed, 22 insertions(+) create mode 100644 base/optional_lock_guard.hpp diff --git a/base/CMakeLists.txt b/base/CMakeLists.txt index cd78655469..a6ac8de491 100644 --- a/base/CMakeLists.txt +++ b/base/CMakeLists.txt @@ -52,6 +52,7 @@ set( normalize_unicode.cpp non_intersecting_intervals.hpp observer_list.hpp + optional_lock_guard.hpp pprof.cpp pprof.hpp random.cpp diff --git a/base/optional_lock_guard.hpp b/base/optional_lock_guard.hpp new file mode 100644 index 0000000000..ac7254eba4 --- /dev/null +++ b/base/optional_lock_guard.hpp @@ -0,0 +1,21 @@ +#pragma once + +#include +#include + +namespace base +{ +template +class OptionalLockGuard +{ +public: + explicit OptionalLockGuard(std::optional & optionalMutex) + : m_optionalGuard(optionalMutex ? std::optional>(*optionalMutex) + : std::nullopt) + { + } + +private: + std::optional> m_optionalGuard; +}; +}