2 * Copyright 2014 Google Inc.
4 * Use of this source code is governed by a BSD-style license that can be
5 * found in the LICENSE file.
8 #ifndef SkDynamicAnnotations_DEFINED
9 #define SkDynamicAnnotations_DEFINED
11 // This file contains macros used to send out-of-band signals to dynamic instrumentation systems,
12 // namely thread sanitizer. This is a cut-down version of the full dynamic_annotations library with
13 // only the features used by Skia.
15 // We check the same define to know to enable the annotations, but prefix all our macros with SK_.
16 #if DYNAMIC_ANNOTATIONS_ENABLED
19 // TSAN provides these hooks.
20 void AnnotateIgnoreReadsBegin(const char* file, int line);
21 void AnnotateIgnoreReadsEnd(const char* file, int line);
24 // SK_ANNOTATE_UNPROTECTED_READ can wrap any variable read to tell TSAN to ignore that it appears to
25 // be a racy read. This should be used only when we can make an external guarantee that though this
26 // particular read is racy, it is being used as part of a mechanism which is thread safe. Examples:
27 // - the first check in double-checked locking;
28 // - checking if a ref count is equal to 1.
29 // Note that in both these cases, we must still add terrifyingly subtle memory barriers to provide
30 // that overall thread safety guarantee. Using this macro to shut TSAN up without providing such an
31 // external guarantee is pretty much never correct.
33 inline T SK_ANNOTATE_UNPROTECTED_READ(const volatile T& x) {
34 AnnotateIgnoreReadsBegin(__FILE__, __LINE__);
36 AnnotateIgnoreReadsEnd(__FILE__, __LINE__);
40 #else // !DYNAMIC_ANNOTATIONS_ENABLED
42 #define SK_ANNOTATE_UNPROTECTED_READ(x) (x)
46 #endif//SkDynamicAnnotations_DEFINED