summaryrefslogtreecommitdiff
path: root/includes/stg/SMP.h
diff options
context:
space:
mode:
authorBen Gamari <ben@smart-cactus.org>2019-09-27 18:49:06 +0000
committerBen Gamari <ben@smart-cactus.org>2020-10-24 21:01:18 -0400
commitedb4b92b218cee5b309866f3d236da30c5621567 (patch)
tree13db4eade35c006e066f838f48de57f1d626355a /includes/stg/SMP.h
parentbf1b0bc78da7dbe5f6fbda54b37a9cb165ff857f (diff)
downloadhaskell-edb4b92b218cee5b309866f3d236da30c5621567.tar.gz
rts/WSDeque: Rewrite with proper atomicswip/tsan/wsdeque
After a few attempts at shoring up the previous implementation, I ended up turning to the literature and now use the proven implementation, > N.M. LĂȘ, A. Pop, A.Cohen, and F.Z. Nardelli. "Correct and Efficient > Work-Stealing for Weak Memory Models". PPoPP'13, February 2013, > ACM 978-1-4503-1922/13/02. Note only is this approach formally proven correct under C11 semantics but it is also proved to be a bit faster in practice.
Diffstat (limited to 'includes/stg/SMP.h')
-rw-r--r--includes/stg/SMP.h15
1 files changed, 15 insertions, 0 deletions
diff --git a/includes/stg/SMP.h b/includes/stg/SMP.h
index fa52a913c4..4679d7986e 100644
--- a/includes/stg/SMP.h
+++ b/includes/stg/SMP.h
@@ -453,6 +453,14 @@ load_load_barrier(void) {
// Non-atomic addition for "approximate" counters that can be lossy
#define NONATOMIC_ADD(ptr,val) RELAXED_STORE(ptr, RELAXED_LOAD(ptr) + val)
+// Explicit fences
+//
+// These are typically necessary only in very specific cases (e.g. WSDeque)
+// where the ordered operations aren't expressive enough to capture the desired
+// ordering.
+#define RELEASE_FENCE() __atomic_thread_fence(__ATOMIC_RELEASE)
+#define SEQ_CST_FENCE() __atomic_thread_fence(__ATOMIC_SEQ_CST)
+
/* ---------------------------------------------------------------------- */
#else /* !THREADED_RTS */
@@ -479,6 +487,10 @@ EXTERN_INLINE void load_load_barrier () {} /* nothing */
// Non-atomic addition for "approximate" counters that can be lossy
#define NONATOMIC_ADD(ptr,val) *ptr += val
+// Fences
+#define RELEASE_FENCE()
+#define SEQ_CST_FENCE()
+
#if !IN_STG_CODE || IN_STGCRUN
INLINE_HEADER StgWord
xchg(StgPtr p, StgWord w)
@@ -527,6 +539,9 @@ atomic_dec(StgVolatilePtr p)
}
#endif
+/* An alias for the C11 declspec */
+#define ATOMIC
+
#define VOLATILE_LOAD(p) ((StgWord)*((StgWord*)(p)))
#endif /* !THREADED_RTS */