mirror of
https://github.com/kidfromjupiter/nearby.git
synced 2026-09-16 15:36:12 -04:00
Roll forward to cl/338482889
Signed-off-by: Alexey Polyudov <apolyudov@google.com> Change-Id: I9850950db8bd84f0904ea1a413151887f52098cf
This commit is contained in:
@@ -0,0 +1,35 @@
|
||||
#ifndef PLATFORM_PUBLIC_CONDITION_VARIABLE_H_
|
||||
#define PLATFORM_PUBLIC_CONDITION_VARIABLE_H_
|
||||
|
||||
#include "platform/api/condition_variable.h"
|
||||
#include "platform/api/platform.h"
|
||||
#include "platform/base/exception.h"
|
||||
#include "platform/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_PUBLIC_CONDITION_VARIABLE_H_
|
||||
Reference in New Issue
Block a user