2 This file is a part of libcds - Concurrent Data Structures library
4 (C) Copyright Maxim Khizhinsky (libcds.dev@gmail.com) 2006-2016
6 Source code repo: http://github.com/khizmax/libcds/
7 Download: http://sourceforge.net/projects/libcds/files/
9 Redistribution and use in source and binary forms, with or without
10 modification, are permitted provided that the following conditions are met:
12 * Redistributions of source code must retain the above copyright notice, this
13 list of conditions and the following disclaimer.
15 * Redistributions in binary form must reproduce the above copyright notice,
16 this list of conditions and the following disclaimer in the documentation
17 and/or other materials provided with the distribution.
19 THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS"
20 AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
21 IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
22 DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE LIABLE
23 FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
24 DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR
25 SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER
26 CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY,
27 OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
28 OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
31 #ifndef CDSLIB_COMPILER_FEATURE_TSAN_H
32 #define CDSLIB_COMPILER_FEATURE_TSAN_H
34 // Thread Sanitizer annotations.
35 // From https://groups.google.com/d/msg/thread-sanitizer/SsrHB7FTnTk/mNTGNLQj-9cJ
39 #ifdef CDS_THREAD_SANITIZER_ENABLED
40 # define CDS_TSAN_ANNOTATE_HAPPENS_BEFORE(addr) AnnotateHappensBefore(__FILE__, __LINE__, reinterpret_cast<void*>(addr))
41 # define CDS_TSAN_ANNOTATE_HAPPENS_AFTER(addr) AnnotateHappensAfter(__FILE__, __LINE__, reinterpret_cast<void*>(addr))
43 # define CDS_TSAN_ANNOTATE_IGNORE_READS_BEGIN AnnotateIgnoreReadsBegin(__FILE__, __LINE__)
44 # define CDS_TSAN_ANNOTATE_IGNORE_READS_END AnnotateIgnoreReadsEnd(__FILE__, __LINE__)
45 # define CDS_TSAN_ANNOTATE_IGNORE_WRITES_BEGIN AnnotateIgnoreWritesBegin(__FILE__, __LINE__)
46 # define CDS_TSAN_ANNOTATE_IGNORE_WRITES_END AnnotateIgnoreWritesEnd(__FILE__, __LINE__)
47 # define CDS_TSAN_ANNOTATE_IGNORE_RW_BEGIN \
48 CDS_TSAN_ANNOTATE_IGNORE_READS_BEGIN; \
49 CDS_TSAN_ANNOTATE_IGNORE_WRITES_BEGIN
50 # define CDS_TSAN_ANNOTATE_IGNORE_RW_END \
51 CDS_TSAN_ANNOTATE_IGNORE_WRITES_END;\
52 CDS_TSAN_ANNOTATE_IGNORE_READS_END
53 # define CDS_TSAN_ANNOTATE_NEW_MEMORY( addr, sz ) AnnotateNewMemory( (char *) __FILE__, __LINE__, reinterpret_cast<void *>(addr), sz )
57 void AnnotateHappensBefore(const char *f, int l, void *addr);
58 void AnnotateHappensAfter(const char *f, int l, void *addr);
60 void AnnotateIgnoreReadsBegin(const char *f, int l);
61 void AnnotateIgnoreReadsEnd(const char *f, int l);
62 void AnnotateIgnoreWritesBegin(const char *f, int l);
63 void AnnotateIgnoreWritesEnd(const char *f, int l);
65 void AnnotateNewMemory(char *f, int l, void * mem, size_t size);
69 #else // CDS_THREAD_SANITIZER_ENABLED
71 # define CDS_TSAN_ANNOTATE_HAPPENS_BEFORE(addr)
72 # define CDS_TSAN_ANNOTATE_HAPPENS_AFTER(addr)
74 # define CDS_TSAN_ANNOTATE_IGNORE_READS_BEGIN
75 # define CDS_TSAN_ANNOTATE_IGNORE_READS_END
76 # define CDS_TSAN_ANNOTATE_IGNORE_WRITES_BEGIN
77 # define CDS_TSAN_ANNOTATE_IGNORE_WRITES_END
78 # define CDS_TSAN_ANNOTATE_IGNORE_RW_BEGIN
79 # define CDS_TSAN_ANNOTATE_IGNORE_RW_END
81 # define CDS_TSAN_ANNOTATE_NEW_MEMORY( addr, sz )
86 #endif // #ifndef CDSLIB_COMPILER_FEATURE_TSAN_H