70 template <
class T,
class Dual>
98 if (!stateMachine.compare_exchange_weak(
101 std::memory_order_seq_cst,
102 std::memory_order_relaxed)) {
107 if (dual ==
nullptr) {
112 expected, kLocked, std::memory_order_seq_cst)) {
121 if ((uintptr_t)
this < (uintptr_t)dual) {
124 while (stateMachine.load(std::memory_order_relaxed) !=
128 stateMachine.store(kLocked, std::memory_order_relaxed);
133 dual->stateMachine.store(
134 kLockedAndLossAcknowledged, std::memory_order_relaxed);
157 stateMachine.store(kUnlocked, std::memory_order_release);
158 if (dual !=
nullptr) {
159 dual->
stateMachine.store(kUnlocked, std::memory_order_release);
171 : stateMachine((other.
lockBoth(), kLocked)),
180 if (dual !=
nullptr) {
185 other.dual =
nullptr;
187 other.stateMachine.store(kUnlocked);
197 if (dual !=
nullptr) {
198 dual->
dual =
nullptr;
206 return !!dual ? std::addressof(dual->
t) :
nullptr;
214 template <
class First,
class Second>
218 template <
class First,
class Second>
222 ef.
dual = std::addressof(es);
223 es.
dual = std::addressof(ef);
227 template <
class T,
class Dual>
237 this->
first = std::addressof(this->e->
t);
238 this->second = !!this->e->
dual ? std::addressof(this->e->
dual->t) :
nullptr;
248 static_cast<std::pair<T*, Dual*>&
>(*this) =
249 static_cast<std::pair<T*, Dual*>&&
>(o);
256 template <
class T,
class Dual>
261 template <
class T,
class Dual>
269 dual(
std::addressof(d)),
270 lock(
std::addressof(l)) {}
274 template <
class First,
class Second>
278 template <
class First,
class Second>
282 storage(First&&
f, Second&&
s) : p((First &&)
f, (Second &&)
s) {}
283 std::tuple<First, Second> p;
288 p, std::get<0>(p->p), std::get<1>(p->p), p->lock);
289 shared_entangled<Second, First> es(
290 p, std::get<1>(p->p), std::get<0>(p->p), p->lock);
294 template <
class T,
class Dual>
298 if (!!e && !!e.
lock) {
304 this->e.
lock->lock();
305 this->
first = this->e.get();
306 this->second = this->e.
dual;
311 template <
class T,
class Dual>
locked_entangled_pair< T, Dual > lock_both(entangled< T, Dual > &e)
locked_entangled_pair(locked_entangled_pair &&o)
static const int kUnlocked
locked_shared_entangled_pair(shared_entangled< T, Dual > &e)
constexpr detail::Map< Move > move
void unlockPointerToDual()
entangled & operator=(const entangled &)=delete
—— Concurrent Priority Queue Implementation ——
auto shared_entangle(First f, Second s) -> shared_entangled_pair< First, Second >
std::pair< shared_entangled< First, Second >, shared_entangled< Second, First >> shared_entangled_pair
auto entangle(First f, Second s) -> entangled_pair< First, Second >
auto lock(Synchronized< D, M > &synchronized, Args &&...args)
shared_entangled(std::shared_ptr< P > &p, T &t, Dual &d, std::mutex &l)
Dual * lockPointerToDual()
locked_entangled_pair & operator=(locked_entangled_pair &&o)
~locked_shared_entangled_pair()
std::atomic< int > stateMachine
shared_entangled< T, Dual > e
std::pair< entangled< First, Second >, entangled< Second, First >> entangled_pair
entangled< Dual, T > * dual
entangled(entangled &&other)
static const int kLockedAndLossAcknowledged
locked_entangled_pair(entangled< T, Dual > &e)
constexpr detail::First first