Browse Source

Lock C++11 implementation based on std::mutex. (#2371)

pull/2384/head
dvadym 6 years ago
committed by AlipmanG
parent
commit
5cb148dc46
1 changed files with 27 additions and 1 deletions
  1. +27
    -1
      cpp/src/phonenumbers/base/synchronization/lock.h

+ 27
- 1
cpp/src/phonenumbers/base/synchronization/lock.h View File

@ -34,10 +34,36 @@ typedef boost::mutex::scoped_lock AutoLock;
#include "phonenumbers/base/logging.h" #include "phonenumbers/base/logging.h"
#include "phonenumbers/base/thread_checker.h" #include "phonenumbers/base/thread_checker.h"
// C++11 Lock implementation based on std::mutex.
#if __cplusplus>=201103L
#include <mutex>
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 // Dummy lock implementation on non-POSIX platforms. If you are running on a
// different platform and care about thread-safety, please compile with // different platform and care about thread-safety, please compile with
// -DI18N_PHONENUMBERS_USE_BOOST. // -DI18N_PHONENUMBERS_USE_BOOST.
#if !defined(__linux__) && !defined(__APPLE__)
#elif !defined(__linux__) && !defined(__APPLE__)
namespace i18n { namespace i18n {
namespace phonenumbers { namespace phonenumbers {


Loading…
Cancel
Save