Files
nearby/cpp/platform_v2/public/condition_variable.h
T
Alexey Polyudov 6b27a508ed nearby: snapshot of cl/317978613
Signed-off-by: Alexey Polyudov <apolyudov@google.com>
Change-Id: I4bf367877a986910bb03e1c54aa972b4bcd59942
2020-06-23 19:52:26 -07:00

36 lines
1.2 KiB
C++

#ifndef PLATFORM_V2_PUBLIC_CONDITION_VARIABLE_H_
#define PLATFORM_V2_PUBLIC_CONDITION_VARIABLE_H_
#include "platform_v2/api/condition_variable.h"
#include "platform_v2/api/platform.h"
#include "platform_v2/base/exception.h"
#include "platform_v2/public/mutex.h"
namespace location {
namespace nearby {
// The ConditionVariable class is a synchronization primitive that can be used
// to block a thread, or multiple threads at the same time, until another thread
// both modifies a shared variable (the condition), and notifies the
// ConditionVariable.
class ConditionVariable final {
public:
using Platform = api::ImplementationPlatform;
explicit ConditionVariable(Mutex* mutex)
: impl_(Platform::CreateConditionVariable(mutex->impl_.get())) {}
ConditionVariable(ConditionVariable&&) = default;
ConditionVariable& operator=(ConditionVariable&&) = default;
void Notify() { impl_->Notify(); }
Exception Wait() { return impl_->Wait(); }
Exception Wait(absl::Duration timeout) { return impl_->Wait(timeout); }
private:
std::unique_ptr<api::ConditionVariable> impl_;
};
} // namespace nearby
} // namespace location
#endif // PLATFORM_V2_PUBLIC_CONDITION_VARIABLE_H_