mirror of
https://github.com/NGSolve/netgen.git
synced 2025-01-11 21:50:34 +05:00
shared loop with relaxed memory ordering
This commit is contained in:
parent
a12e9bec61
commit
ad6ffaac05
@ -462,22 +462,26 @@ public:
|
|||||||
// return IntRange(begin, end);
|
// return IntRange(begin, end);
|
||||||
// }
|
// }
|
||||||
|
|
||||||
bool PopFirst (size_t & first)
|
bool PopFirst (size_t & hfirst)
|
||||||
{
|
{
|
||||||
// first = begin++;
|
// first = begin++;
|
||||||
// return first < end;
|
// return first < end;
|
||||||
|
|
||||||
first = begin;
|
size_t first = begin.load(std::memory_order_relaxed);
|
||||||
|
|
||||||
size_t nextfirst = first+1;
|
size_t nextfirst = first+1;
|
||||||
if (first >= end) nextfirst = std::numeric_limits<size_t>::max()-1;
|
if (first >= end) nextfirst = std::numeric_limits<size_t>::max()-1;
|
||||||
|
|
||||||
while (!begin.compare_exchange_weak (first, nextfirst))
|
// while (!begin.compare_exchange_weak (first, nextfirst))
|
||||||
|
while (!begin.compare_exchange_weak (first, nextfirst,
|
||||||
|
std::memory_order_relaxed,
|
||||||
|
std::memory_order_relaxed))
|
||||||
{
|
{
|
||||||
first = begin;
|
first = begin;
|
||||||
nextfirst = first+1;
|
nextfirst = first+1;
|
||||||
if (nextfirst >= end) nextfirst = std::numeric_limits<size_t>::max()-1;
|
if (nextfirst >= end) nextfirst = std::numeric_limits<size_t>::max()-1;
|
||||||
}
|
}
|
||||||
|
hfirst = first;
|
||||||
return first < end;
|
return first < end;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
Loading…
Reference in New Issue
Block a user