Honeycomb  0.1
Component-Model Framework
Lock.h
Go to the documentation of this file.
1 // Honeycomb, Copyright (C) 2015 NewGamePlus Inc. Distributed under the Boost Software License v1.0.
2 #pragma once
3 
5 
6 namespace honey
7 {
8 
10 
33 class ConditionLock : public Condition, public Mutex
34 {
35 public:
37 
38  //Undefined
40  template<class Rep, class Period>
42  template<class Clock, class Dur>
44 
46  void wait() { wait(MonoClock::TimePoint::max()); }
47  template<class Rep, class Period>
48  bool wait(Duration<Rep,Period> time) { return wait(time == time.max() ? MonoClock::TimePoint::max() : MonoClock::now() + time); }
49  template<class Clock, class Dur>
51  {
52  //Scoping used to ensure state is returned to normal if an exception is thrown
54  auto _ = ScopeGuard(lock::releaseGuard(lock));
55  return Condition::wait(lock, time);
56  } //lock.release();
57 };
58 
59 }
A scoped lock that references any lockable. Locks on construction and unlocks on destruction.
Definition: Mutex.h:10
Method to synchronize threads. Condition variables eliminate the need for repeated polling to check t...
Definition: Condition.h:18
TimePoint represented by a duration since a clock's epoch time.
Definition: TimePoint.h:11
static TimePoint now()
Get current time.
Definition: Clock.h:48
function< void()> releaseGuard(Lock &lock)
Definition: Unique.h:31
void lock()
Acquire the lock. Thread suspends until lock becomes available.
Definition: Mutex.h:32
static auto _
Definition: Module.cpp:8
Lock that is bound to a single condition. This is the common usage case of condition variables...
Definition: Lock.h:33
static constexpr Duration max()
Maximum duration (positive reps)
Definition: Duration.h:86
bool wait(Duration< Rep, Period > time)
Definition: Lock.h:48
void wait()
No lock arg required.
Definition: Lock.h:46
Duration represented by repetitions of a period. The period must be a ratio.
Definition: Duration.h:7
void wait(UniqueLock< Mutex > &lock)
Release lock and wait until thread is signaled.
Definition: Condition.h:28
UniqueLock< ConditionLock > Scoped
Definition: Lock.h:36
A thread lock where the lock is acquired by suspending thread execution until it becomes available...
Definition: Mutex.h:17
bool wait(TimePoint< Clock, Dur > time)
Definition: Lock.h:50
Global Honeycomb namespace.
Already locked.