Honeycomb  0.1
Component-Model Framework
TimedMutex.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/Atomic.h"
6 
7 namespace honey
8 {
9 
11 class TimedMutex : public Mutex
12 {
13 public:
15 
16  TimedMutex() : _tryWaitCount(0) {}
19 
21  TimedMutex& operator=(const TimedMutex&) { return *this; }
22 
24  void lock() { Mutex::lock(); }
26  void unlock();
28  bool tryLock() { return Mutex::tryLock(); }
30  bool tryLock(MonoClock::Duration time) { return tryLock(time == time.max() ? MonoClock::TimePoint::max() : MonoClock::now() + time); }
32  bool tryLock(MonoClock::TimePoint time);
33 
34 private:
35  Atomic<int> _tryWaitCount;
36  ConditionLock _tryCond;
37 };
38 
39 }
A scoped lock that references any lockable. Locks on construction and unlocks on destruction.
Definition: Mutex.h:10
void unlock()
Release the lock.
Definition: TimedMutex.cpp:8
static TimePoint now()
Get current time.
Definition: Clock.h:48
void lock()
Acquire the lock. Thread suspends until lock becomes available.
Definition: TimedMutex.h:24
bool tryLock()
Attempt to acquire the lock, returns immediately. Returns true if the lock was acquired, false otherwise.
Definition: TimedMutex.h:28
Super::TimePoint TimePoint
Definition: Clock.h:40
void lock()
Acquire the lock. Thread suspends until lock becomes available.
Definition: Mutex.h:32
TimedMutex()
Definition: TimedMutex.h:16
TimedMutex & operator=(const TimedMutex &)
Can't copy, silently does nothing.
Definition: TimedMutex.h:21
Lock that is bound to a single condition. This is the common usage case of condition variables...
Definition: Lock.h:33
A mutex that has a timed try-lock.
Definition: TimedMutex.h:11
bool tryLock(MonoClock::Duration time)
Attempt to acquire the lock for an amount of time. Returns true if the lock was acquired, false if timed out.
Definition: TimedMutex.h:30
UniqueLock< TimedMutex > Scoped
Definition: TimedMutex.h:14
bool tryLock()
Attempt to acquire the lock, returns immediately. Returns true if the lock was acquired, false otherwise.
Definition: Mutex.h:36
A thread lock where the lock is acquired by suspending thread execution until it becomes available...
Definition: Mutex.h:17
TimePoint::Duration Duration
Definition: Clock.h:41
Global Honeycomb namespace.
TimedMutex(const TimedMutex &)
Can't copy, silently inits to default.
Definition: TimedMutex.h:18