summaryrefslogtreecommitdiff
path: root/rts/include
diff options
context:
space:
mode:
authorBen Gamari <ben@smart-cactus.org>2022-11-10 18:29:45 -0500
committerMarge Bot <ben+marge-bot@smart-cactus.org>2022-12-16 16:12:45 -0500
commit86f20258ab7dbfb56e323ee811e9eaef80b077d3 (patch)
tree48ffebf1bd6adea439e3197cfa3a9d14eabacc2b /rts/include
parent605d954722a314c0da59ea07efc26d8a7cb59296 (diff)
downloadhaskell-86f20258ab7dbfb56e323ee811e9eaef80b077d3.tar.gz
rts/Timer: Always use atomic operations
As noted in #22447, the existence of the pthread-based ITimer implementation means that we cannot assume that the program is single-threaded.
Diffstat (limited to 'rts/include')
-rw-r--r--rts/include/stg/SMP.h19
1 files changed, 19 insertions, 0 deletions
diff --git a/rts/include/stg/SMP.h b/rts/include/stg/SMP.h
index 0800c87786..c9ff736032 100644
--- a/rts/include/stg/SMP.h
+++ b/rts/include/stg/SMP.h
@@ -18,6 +18,25 @@ void arm_atomic_spin_lock(void);
void arm_atomic_spin_unlock(void);
#endif
+// Unconditionally atomic operations
+// These are atomic even in the non-threaded RTS. These are necessary in the
+// Proftimer implementation, which may be called from the pthreads-based
+// ITimer implementation.
+#define RELAXED_LOAD_ALWAYS(ptr) __atomic_load_n(ptr, __ATOMIC_RELAXED)
+#define RELAXED_STORE_ALWAYS(ptr,val) __atomic_store_n(ptr, val, __ATOMIC_RELAXED)
+#define RELAXED_ADD_ALWAYS(ptr,val) __atomic_add_fetch(ptr, val, __ATOMIC_RELAXED)
+
+// Acquire/release atomic operations
+#define ACQUIRE_LOAD_ALWAYS(ptr) __atomic_load_n(ptr, __ATOMIC_ACQUIRE)
+#define RELEASE_STORE_ALWAYS(ptr,val) __atomic_store_n(ptr, val, __ATOMIC_RELEASE)
+
+// Sequentially consistent atomic operations
+#define SEQ_CST_LOAD_ALWAYS(ptr) __atomic_load_n(ptr, __ATOMIC_SEQ_CST)
+#define SEQ_CST_STORE_ALWAYS(ptr,val) __atomic_store_n(ptr, val, __ATOMIC_SEQ_CST)
+#define SEQ_CST_ADD_ALWAYS(ptr,val) __atomic_add_fetch(ptr, val, __ATOMIC_SEQ_CST)
+#define SEQ_CST_SUB_ALWAYS(ptr,val) __atomic_sub_fetch(ptr, val, __ATOMIC_SEQ_CST)
+
+
#if defined(THREADED_RTS)
/* ----------------------------------------------------------------------------