Honeycomb  0.1
Component-Model Framework
Any.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 
11 {
12 public:
13  void signal() { Mutex::Scoped _(_lock); _cond.signal(); }
14  void broadcast() { Mutex::Scoped _(_lock); _cond.broadcast(); }
15 
16  template<class Lockable>
17  void wait(Lockable& lock) { wait(lock, MonoClock::TimePoint::max()); }
18  template<class Lockable, class Rep, class Period>
19  bool wait(Lockable& lock, Duration<Rep,Period> time) { return wait(lock, time == time.max() ? MonoClock::TimePoint::max() : MonoClock::now() + time); }
20  template<class Lockable, class Clock, class Dur>
21  bool wait(Lockable& external, TimePoint<Clock,Dur> time)
22  {
23  //Scoping used to ensure state is returned to normal if an exception is thrown
24  Mutex::Scoped internal(_lock);
25  external.unlock();
26  auto _ = ScopeGuard(lock::lockGuard(external));
28  return _cond.wait(internal, time);
29  } //internal.unlock(); external.lock();
30 
31 private:
32  Condition _cond;
33  Mutex _lock;
34 };
35 
36 }
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
Condition that can be used with any kind of lock. Slightly slower than the default Condition class...
Definition: Any.h:10
static auto _
Definition: Module.cpp:8
bool wait(Lockable &lock, Duration< Rep, Period > time)
Definition: Any.h:19
void signal()
Definition: Any.h:13
void broadcast()
Signal all waiting threads to resume, all resumed threads attempt to acquire the lock.
Definition: Condition.h:25
function< void()> lockGuard(Lock &lock)
Definition: Unique.h:27
void unlock()
Definition: Unique.h:103
static constexpr Duration max()
Maximum duration (positive reps)
Definition: Duration.h:86
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
bool wait(Lockable &external, TimePoint< Clock, Dur > time)
Definition: Any.h:21
A thread lock where the lock is acquired by suspending thread execution until it becomes available...
Definition: Mutex.h:17
void signal()
Signal one waiting thread to resume, resumed thread attempts to acquire the lock. ...
Definition: Condition.h:23
void wait(Lockable &lock)
Definition: Any.h:17
Global Honeycomb namespace.
Already locked.
void broadcast()
Definition: Any.h:14