summaryrefslogtreecommitdiff
path: root/lib/seqlock.c
diff options
context:
space:
mode:
authorRuss White <russ@riw.us>2024-07-09 11:36:24 -0400
committerGitHub <noreply@github.com>2024-07-09 11:36:24 -0400
commit22db85a714adb3022963eff707cf6140000c5881 (patch)
treedd148d2ffdc879938a24810a01b72f28fee9d78d /lib/seqlock.c
parent8ca262943f09e20b7e34a4eceb255b9d0ce757a0 (diff)
parente14c94f2b77692126210f4b7b51cf097d7f847e0 (diff)
Merge pull request #16258 from opensourcerouting/tsan-20240620
lib, tests: fix some b0rked tests, then fix TSAN warnings
Diffstat (limited to 'lib/seqlock.c')
-rw-r--r--lib/seqlock.c33
1 files changed, 33 insertions, 0 deletions
diff --git a/lib/seqlock.c b/lib/seqlock.c
index 62ce316920..e74e6718bf 100644
--- a/lib/seqlock.c
+++ b/lib/seqlock.c
@@ -26,6 +26,39 @@
* OS specific synchronization wrappers *
****************************************/
+#ifndef __has_feature /* not available on old GCC */
+#define __has_feature(x) 0
+#endif
+
+#if (defined(__SANITIZE_THREAD__) || __has_feature(thread_sanitizer))
+/* TSAN really does not understand what is going on with the low-level
+ * futex/umtx calls. This leads to a whole bunch of warnings, a lot of which
+ * also have _extremely_ misleading text - since TSAN does not understand that
+ * there is in fact a synchronization primitive involved, it can end up pulling
+ * in completely unrelated things.
+ *
+ * What does work is the "unsupported platform" seqlock implementation based
+ * on a pthread mutex + condvar, since TSAN of course suppports these.
+ *
+ * It may be possible to also fix this with TSAN annotations (__tsan_acquire
+ * and __tsan_release), but using those (correctly) is not easy either, and
+ * for now just get things rolling.
+ */
+
+#ifdef HAVE_SYNC_LINUX_FUTEX
+#undef HAVE_SYNC_LINUX_FUTEX
+#endif
+
+#ifdef HAVE_SYNC_OPENBSD_FUTEX
+#undef HAVE_SYNC_OPENBSD_FUTEX
+#endif
+
+#ifdef HAVE_SYNC_UMTX_OP
+#undef HAVE_SYNC_UMTX_OP
+#endif
+
+#endif /* TSAN */
+
/*
* Linux: sys_futex()
*/