Honeycomb  0.1
Component-Model Framework
Mutex.h
Go to the documentation of this file.
1 // Honeycomb, Copyright (C) 2013 Daniel Carter. Distributed under the Boost Software License v1.0.
2 #pragma once
3 
4 #include "Honey/Thread/Atomic.h"
6 
7 namespace honey
8 {
9 
10 class Condition;
11 class Mutex;
12 
14 namespace platform
15 {
16 
18 class Mutex
19 {
20 public:
21  typedef CRITICAL_SECTION Handle;
22 
23  Mutex(bool timed);
24  virtual ~Mutex();
25 
26  void lock();
27  void unlock();
28  bool tryLock();
29  bool tryLock(honey::MonoClock::Duration time) { return tryLock(honey::MonoClock::now() + time); }
31  Handle& handle() { return _handle; }
32 
33 private:
34  Handle _handle;
35  atomic::Var<int> _tryWaitCount;
36  UniquePtr<honey::Mutex> _tryLock;
37  UniquePtr<honey::Condition> _tryCond;
38 };
39 
40 } }
static TimePoint now()
Get current time.
Definition: Clock.h:48
void lock(Locks &&...locks)
Lock all lockables safely without deadlocking.
Definition: Util.h:110
Super::TimePoint TimePoint
Definition: Clock.h:40
TimePoint::Duration Duration
Definition: Clock.h:41
Global Honeycomb namespace.
int tryLock(Lock &l, Locks &...ls)
Try to lock all lockables. Locks either all or none.
Definition: Util.h:26