mirror of
https://github.com/kidfromjupiter/nearby.git
synced 2026-09-15 07:06:11 -04:00
Signed-off-by: Alexey Polyudov <apolyudov@google.com> Change-Id: I8936b527079074d5c3af5531b9245063767cc4a7
32 lines
818 B
C++
32 lines
818 B
C++
#ifndef PLATFORM_V2_PUBLIC_MUTEX_LOCK_H_
|
|
#define PLATFORM_V2_PUBLIC_MUTEX_LOCK_H_
|
|
|
|
#include "platform_v2/api/mutex.h"
|
|
#include "platform_v2/public/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 MutexLock final {
|
|
public:
|
|
explicit MutexLock(Mutex* mutex) ABSL_EXCLUSIVE_LOCK_FUNCTION(mutex)
|
|
: mutex_(mutex->impl_.get()) {
|
|
mutex_->Lock();
|
|
}
|
|
explicit MutexLock(RecursiveMutex* mutex) ABSL_EXCLUSIVE_LOCK_FUNCTION(mutex)
|
|
: mutex_(mutex->impl_.get()) {
|
|
mutex_->Lock();
|
|
}
|
|
~MutexLock() ABSL_UNLOCK_FUNCTION() { mutex_->Unlock(); }
|
|
|
|
private:
|
|
api::Mutex* mutex_;
|
|
};
|
|
|
|
} // namespace nearby
|
|
} // namespace location
|
|
|
|
#endif // PLATFORM_V2_PUBLIC_MUTEX_LOCK_H_
|