Files
nearby/cpp/platform/base/base_mutex_lock.h
T
Alexey Polyudov 2155b3ddeb Roll forward to cl/338482889
Signed-off-by: Alexey Polyudov <apolyudov@google.com>
Change-Id: I9850950db8bd84f0904ea1a413151887f52098cf
2020-10-22 10:47:34 -07:00

27 lines
640 B
C++

#ifndef PLATFORM_BASE_BASE_MUTEX_LOCK_H_
#define PLATFORM_BASE_BASE_MUTEX_LOCK_H_
#include "platform/api/mutex.h"
#include "absl/base/thread_annotations.h"
namespace location {
namespace nearby {
// An RAII mechanism to acquire a Lock over a block of code.
class ABSL_SCOPED_LOCKABLE BaseMutexLock final {
public:
explicit BaseMutexLock(api::Mutex* mutex) ABSL_EXCLUSIVE_LOCK_FUNCTION(mutex)
: mutex_(mutex) {
mutex_->Lock();
}
~BaseMutexLock() ABSL_UNLOCK_FUNCTION() { mutex_->Unlock(); }
private:
api::Mutex* mutex_;
};
} // namespace nearby
} // namespace location
#endif // PLATFORM_BASE_BASE_MUTEX_LOCK_H_