Skip to content
Snippets Groups Projects
Commit 9a255dd5 authored by Florian Schmaus's avatar Florian Schmaus
Browse files

[Fiber] Improve memory order of reference counter

parent 9bb8f489
No related branches found
No related tags found
1 merge request!195[LAWS/Fiber] Introduce the concept of Multi-Fiber
......@@ -91,15 +91,23 @@ class ALIGN_TO_CACHE_LINE Fiber : public Logger<LogSubsystem::F> {
return runnable.exchange(false);
}
inline auto doAtomicIncrRefCount() -> unsigned int {
inline void doAtomicIncrRefCount() {
assert(referenceCounter < UINT_MAX);
isMulti = true;
return ++referenceCounter;
// Note: Although the first impulse is to prevent the re-ordering
// of the isMulti store after the reference counter modification,
// this *should* not be necessary. The sychronization point where
// this ordering is guranteed is, when the fiber is put in a
// concurrent queue. There the queue must gurantee that all
// previous stores are visible at the time the fiber appears in
// the queue to other threads.
referenceCounter.fetch_add(1, std::memory_order_relaxed);
}
inline auto doAtomicDecrRefCount() -> unsigned int {
assert(referenceCounter > 0);
return --referenceCounter;
auto previous = referenceCounter.fetch_sub(1, std::memory_order_acq_rel);
return previous - 1;
}
template <LogSubsystem>
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment