From 5cb148dc4631936711e9384f4b569a2e01d04726 Mon Sep 17 00:00:00 2001 From: dvadym <53558779+dvadym@users.noreply.github.com> Date: Mon, 19 Aug 2019 20:30:31 +0200 Subject: [PATCH] Lock C++11 implementation based on std::mutex. (#2371) --- .../phonenumbers/base/synchronization/lock.h | 28 ++++++++++++++++++- 1 file changed, 27 insertions(+), 1 deletion(-) diff --git a/cpp/src/phonenumbers/base/synchronization/lock.h b/cpp/src/phonenumbers/base/synchronization/lock.h index 296421cd5..1893f1b3c 100644 --- a/cpp/src/phonenumbers/base/synchronization/lock.h +++ b/cpp/src/phonenumbers/base/synchronization/lock.h @@ -34,10 +34,36 @@ typedef boost::mutex::scoped_lock AutoLock; #include "phonenumbers/base/logging.h" #include "phonenumbers/base/thread_checker.h" +// C++11 Lock implementation based on std::mutex. +#if __cplusplus>=201103L +#include + +namespace i18n { +namespace phonenumbers { + +class Lock { +public: + Lock() = default; + + void Acquire() const { + mutex_.lock(); + } + + void Release() const { + mutex_.unlock(); + } + +private: + mutable std::mutex mutex_; +}; + +} // namespace phonenumbers +} // namespace i18n + // Dummy lock implementation on non-POSIX platforms. If you are running on a // different platform and care about thread-safety, please compile with // -DI18N_PHONENUMBERS_USE_BOOST. -#if !defined(__linux__) && !defined(__APPLE__) +#elif !defined(__linux__) && !defined(__APPLE__) namespace i18n { namespace phonenumbers {