Honeycomb  0.1
Component-Model Framework
Condition.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 
4 #include "Honey/Thread/Thread.h"
6 #include "Honey/Thread/Condition/platform/Condition.h"
7 
8 namespace honey
9 {
10 
12 
18 class Condition : platform::Condition, mt::NoCopy
19 {
20  typedef platform::Condition Super;
21 public:
23  void signal() { Super::signal(); }
25  void broadcast() { Super::broadcast(); }
26 
28  void wait(UniqueLock<Mutex>& lock) { wait(lock, MonoClock::TimePoint::max()); }
30  template<class Rep, class Period>
31  bool wait(UniqueLock<Mutex>& lock, Duration<Rep,Period> time) { return wait(lock, time == time.max() ? MonoClock::TimePoint::max() : MonoClock::now() + time); }
33  template<class Clock, class Dur>
35  {
36  thread::priv::InterruptWait _(Thread::current(), *this, lock.mutex());
38  bool res = Super::wait(lock, time);
40  return res;
41  }
42 };
43 
44 }
Lockable & mutex()
Get the referenced mutex.
Definition: Unique.h:140
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
bool wait(UniqueLock< Mutex > &lock, Duration< Rep, Period > time)
Release lock and wait until thread is signaled or until an amount of time has passed. Returns true if signaled, false if timed out.
Definition: Condition.h:31
Inherit to declare that class is not copyable.
Definition: Meta.h:286
static auto _
Definition: Module.cpp:8
void broadcast()
Signal all waiting threads to resume, all resumed threads attempt to acquire the lock.
Definition: Condition.h:25
static Thread & current()
Get the thread object of the calling thread.
Definition: Thread.h:156
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(UniqueLock< Mutex > &lock, TimePoint< Clock, Dur > time)
Release lock and wait until thread is signaled or until a certain time. Returns true if signaled...
Definition: Condition.h:34
void signal()
Signal one waiting thread to resume, resumed thread attempts to acquire the lock. ...
Definition: Condition.h:23
Global Honeycomb namespace.
void interruptPoint()
Throw an exception if interrupt is enabled and has been requested in this thread. ...
Definition: Thread.cpp:46