18 inline int tryLock() {
return -1; }
25 template<
class Lock,
class... Locks,
typename mt::disable_if<mt::isRange<Lock>::value,
int>::type=0>
31 if (failed >= 0)
return failed+1;
40 template<class Range, typename std::enable_if<mt::isRange<Range>::value,
int>::type=0>
43 auto& begin = honey::begin(
range);
44 auto& end = honey::end(
range);
45 if (begin == end)
return end;
47 if (!lock)
return begin;
49 if (failed == end) lock.
release();
61 template<
class Lock,
class... Locks,
typename mt::disable_if<mt::isRange<Lock>::value,
int>::type=0>
62 int lockTest(Lock& l, Locks&... ls)
66 if (failed >= 0)
return failed+1;
72 template<class Range, typename std::enable_if<mt::isRange<Range>::value,
int>::type=0>
75 auto& begin = honey::begin(
range);
76 auto& end = honey::end(
range);
77 if (begin == end)
return end;
78 UniqueLock<mt_iterOf(range)::value_type>
lock(*begin);
80 if (failed == end)
lock.release();
84 template<
class Locks,
szt... Seq>
85 void lock(Locks&& locks, mt::idxseq<Seq...>)
87 auto switch_ = mt::make_array<function<int ()>>([&]() ->
int
89 const int offset = Seq;
91 if ((failed = priv::lockTest(
get<(offset+Seq) %
sizeof...(Seq)>(locks)...)) == -1)
return -1;
92 return (offset+failed) %
sizeof...(Seq);
95 while(lockFirst >= 0) lockFirst = switch_[lockFirst]();
113 template<class Range, typename std::enable_if<mt::isRange<Range>::value,
int>::type=0>
116 auto lockFirst = begin(
range);
120 if ((lockFirst = priv::lockTest(it)) == end(it).iter())
break;
A scoped lock that references any lockable. Locks on construction and unlocks on destruction.
Definition: Mutex.h:10
Try to lock (non-blocking)
void lock(Locks &&...locks)
Lock all lockables safely without deadlocking.
Definition: Util.h:110
auto ringRange(Range &&range, const Iter &cur) -> Range_< RingIter< Range, Iter >, RingIter< Range, Iter >>
Create an iterator adapter range that does one full cyclic loop starting at cur through the range...
Definition: Range.h:704
Lockable & release()
Release the mutex from further operations. The mutex will no longer be owned and its state will remai...
Definition: Unique.h:147
std::enable_if< mt::isIterator< Iter1 >::value, Range_< Iter1, Iter2 > >::type range(Iter1 &&first, Iter2 &&last)
Range from iterators [first, last)
Definition: Range.h:116
void lock(Range &&range)
Lock all lockables in a range safely without deadlocking.
Definition: Util.h:114
#define mt_iterOf(Range)
iterOf for values
Definition: Range.h:33
size_t szt
Size type, shorthand for size_t.
Definition: Core.h:90
Global Honeycomb namespace.
int tryLock(Lock &l, Locks &...ls)
Try to lock all lockables. Locks either all or none.
Definition: Util.h:26