Honeycomb  0.1
Component-Model Framework
Enumerations | Functions
honey::lock Namespace Reference

Mutex lock util. More...

Enumerations

enum  Op { Op::lock, Op::tryLock, Op::adopt, Op::defer }
 

Functions

template<class Lock , class... Locks, typename mt::disable_if< mt::isRange< Lock >::value, int >::type = 0>
int tryLock (Lock &l, Locks &...ls)
 Try to lock all lockables. Locks either all or none. More...
 
template<class Range , typename std::enable_if< mt::isRange< Range >::value, int >::type = 0>
auto tryLock (Range &&range) -> mt_iterOf(range)
 Try to lock all lockables in a range. Locks either all or none. More...
 
template<class... Locks, typename mt::disable_if< mt::isRange< mt::typeAt< 0, Locks... >>::value, int >::type = 0>
void lock (Locks &&...locks)
 Lock all lockables safely without deadlocking. More...
 
template<class Range , typename std::enable_if< mt::isRange< Range >::value, int >::type = 0>
void lock (Range &&range)
 Lock all lockables in a range safely without deadlocking. More...
 
ScopeGuard functors
template<class Lock >
function< void()> lockGuard (Lock &lock)
 
template<class Lock >
function< void()> unlockGuard (Lock &lock)
 
template<class Lock >
function< void()> releaseGuard (Lock &lock)
 

Detailed Description

Mutex lock util.

Enumeration Type Documentation

enum honey::lock::Op
strong
Enumerator
lock 

Lock (blocking)

tryLock 

Try to lock (non-blocking)

adopt 

Already locked.

defer 

Not yet locked, will lock manually.

Function Documentation

template<class... Locks, typename mt::disable_if< mt::isRange< mt::typeAt< 0, Locks... >>::value, int >::type = 0>
void honey::lock::lock ( Locks &&...  locks)

Lock all lockables safely without deadlocking.

Deadlock can be avoided by waiting only for the first lock, then trying to lock the others without waiting. If any of the others fail, restart and wait for a failed lock instead. For example:

Lock L1 and then call:                          tryLock(L2,L3,L4,L5)
If L2 failed then restart, lock L2 and call:    tryLock(L3,L4,L5,L1)
template<class Range , typename std::enable_if< mt::isRange< Range >::value, int >::type = 0>
void honey::lock::lock ( Range &&  range)

Lock all lockables in a range safely without deadlocking.

template<class Lock >
function<void ()> honey::lock::lockGuard ( Lock &  lock)
template<class Lock >
function<void ()> honey::lock::releaseGuard ( Lock &  lock)
template<class Lock , class... Locks, typename mt::disable_if< mt::isRange< Lock >::value, int >::type = 0>
int honey::lock::tryLock ( Lock &  l,
Locks &...  ls 
)

Try to lock all lockables. Locks either all or none.

Returns the zero-based index of the first failed lock, or -1 if all locks were successful.

template<class Range , typename std::enable_if< mt::isRange< Range >::value, int >::type = 0>
auto honey::lock::tryLock ( Range &&  range) -> mt_iterOf(range)

Try to lock all lockables in a range. Locks either all or none.

Returns an iterator to the first failed lock, or end if all locks were successful.

template<class Lock >
function<void ()> honey::lock::unlockGuard ( Lock &  lock)