dispenso
A library for task parallelism
 
Loading...
Searching...
No Matches
tsan_annotations.h
Go to the documentation of this file.
1/*
2 * Copyright (c) Meta Platforms, Inc. and affiliates.
3 *
4 * This source code is licensed under the MIT license found in the
5 * LICENSE file in the root directory of this source tree.
6 */
7
20#pragma once
21
22#include <dispenso/platform.h>
23
24#if defined(__SANITIZE_THREAD__)
25#define DISPENSO_HAS_TSAN 1
26#elif defined(__has_feature)
27#if __has_feature(thread_sanitizer)
28#define DISPENSO_HAS_TSAN 1
29#else
30#define DISPENSO_HAS_TSAN 0
31#endif // TSAN
32#else
33#define DISPENSO_HAS_TSAN 0
34#endif // feature
35
36#if DISPENSO_HAS_TSAN
37
38namespace dispenso {
39namespace detail {
40
41DISPENSO_DLL_ACCESS void annotateIgnoreWritesBegin(const char* f, int l);
42DISPENSO_DLL_ACCESS void annotateIgnoreWritesEnd(const char* f, int l);
43DISPENSO_DLL_ACCESS void annotateIgnoreReadsBegin(const char* f, int l);
44DISPENSO_DLL_ACCESS void annotateIgnoreReadsEnd(const char* f, int l);
45DISPENSO_DLL_ACCESS void
46annotateNewMemory(const char* f, int l, const volatile void* address, long size);
47DISPENSO_DLL_ACCESS void annotateHappensBefore(const char* f, int l, const volatile void* address);
48DISPENSO_DLL_ACCESS void annotateHappensAfter(const char* f, int l, const volatile void* address);
49
50} // namespace detail
51} // namespace dispenso
52
53#define DISPENSO_TSAN_ANNOTATE_IGNORE_WRITES_BEGIN() \
54 ::dispenso::detail::annotateIgnoreWritesBegin(__FILE__, __LINE__)
55#define DISPENSO_TSAN_ANNOTATE_IGNORE_WRITES_END() \
56 ::dispenso::detail::annotateIgnoreWritesEnd(__FILE__, __LINE__)
57#define DISPENSO_TSAN_ANNOTATE_IGNORE_READS_BEGIN() \
58 ::dispenso::detail::annotateIgnoreReadsBegin(__FILE__, __LINE__)
59#define DISPENSO_TSAN_ANNOTATE_IGNORE_READS_END() \
60 ::dispenso::detail::annotateIgnoreReadsEnd(__FILE__, __LINE__)
61#define DISPENSO_TSAN_ANNOTATE_NEW_MEMORY(address, size) \
62 ::dispenso::detail::annotateNewMemory(__FILE__, __LINE__, address, size)
63#define DISPENSO_TSAN_ANNOTATE_HAPPENS_BEFORE(address) \
64 ::dispenso::detail::annotateHappensBefore(__FILE__, __LINE__, address)
65#define DISPENSO_TSAN_ANNOTATE_HAPPENS_AFTER(address) \
66 ::dispenso::detail::annotateHappensAfter(__FILE__, __LINE__, address)
67
68#else
69
70#define DISPENSO_TSAN_ANNOTATE_IGNORE_WRITES_BEGIN()
71#define DISPENSO_TSAN_ANNOTATE_IGNORE_WRITES_END()
72#define DISPENSO_TSAN_ANNOTATE_IGNORE_READS_BEGIN()
73#define DISPENSO_TSAN_ANNOTATE_IGNORE_READS_END()
74#define DISPENSO_TSAN_ANNOTATE_NEW_MEMORY(address, size)
75#define DISPENSO_TSAN_ANNOTATE_HAPPENS_BEFORE(address)
76#define DISPENSO_TSAN_ANNOTATE_HAPPENS_AFTER(address)
77
78#endif // DISPENSO_HAS_TSAN