| OLD | NEW |
| (Empty) |
| 1 /* | |
| 2 * Copyright 2014 Google Inc. | |
| 3 * | |
| 4 * Use of this source code is governed by a BSD-style license that can be | |
| 5 * found in the LICENSE file. | |
| 6 */ | |
| 7 | |
| 8 #ifndef SkDynamicAnnotations_DEFINED | |
| 9 #define SkDynamicAnnotations_DEFINED | |
| 10 | |
| 11 // Make sure we see anything set via SkUserConfig.h (e.g. DYNAMIC_ANNOTATIONS_EN
ABLED). | |
| 12 #include "SkTypes.h" | |
| 13 | |
| 14 // This file contains macros used to send out-of-band signals to dynamic instrum
entation systems, | |
| 15 // namely thread sanitizer. This is a cut-down version of the full dynamic_anno
tations library with | |
| 16 // only the features used by Skia. | |
| 17 | |
| 18 #if DYNAMIC_ANNOTATIONS_ENABLED | |
| 19 | |
| 20 extern "C" { | |
| 21 // TSAN provides these hooks. | |
| 22 void AnnotateIgnoreReadsBegin(const char* file, int line); | |
| 23 void AnnotateIgnoreReadsEnd(const char* file, int line); | |
| 24 void AnnotateIgnoreWritesBegin(const char* file, int line); | |
| 25 void AnnotateIgnoreWritesEnd(const char* file, int line); | |
| 26 } // extern "C" | |
| 27 | |
| 28 // SK_ANNOTATE_UNPROTECTED_READ can wrap any variable read to tell TSAN to ignor
e that it appears to | |
| 29 // be a racy read. This should be used only when we can make an external guaran
tee that though this | |
| 30 // particular read is racy, it is being used as part of a mechanism which is thr
ead safe. Examples: | |
| 31 // - the first check in double-checked locking; | |
| 32 // - checking if a ref count is equal to 1. | |
| 33 // Note that in both these cases, we must still add terrifyingly subtle memory b
arriers to provide | |
| 34 // that overall thread safety guarantee. Using this macro to shut TSAN up witho
ut providing such an | |
| 35 // external guarantee is pretty much never correct. | |
| 36 template <typename T> | |
| 37 inline T SK_ANNOTATE_UNPROTECTED_READ(const volatile T& x) { | |
| 38 AnnotateIgnoreReadsBegin(__FILE__, __LINE__); | |
| 39 T read = x; | |
| 40 AnnotateIgnoreReadsEnd(__FILE__, __LINE__); | |
| 41 return read; | |
| 42 } | |
| 43 | |
| 44 // Like SK_ANNOTATE_UNPROTECTED_READ, but for writes. | |
| 45 template <typename T> | |
| 46 inline void SK_ANNOTATE_UNPROTECTED_WRITE(T* ptr, const T& val) { | |
| 47 AnnotateIgnoreWritesBegin(__FILE__, __LINE__); | |
| 48 *ptr = val; | |
| 49 AnnotateIgnoreWritesEnd(__FILE__, __LINE__); | |
| 50 } | |
| 51 | |
| 52 #else // !DYNAMIC_ANNOTATIONS_ENABLED | |
| 53 | |
| 54 #define SK_ANNOTATE_UNPROTECTED_READ(x) (x) | |
| 55 #define SK_ANNOTATE_UNPROTECTED_WRITE(ptr, val) *(ptr) = (val) | |
| 56 | |
| 57 #endif | |
| 58 | |
| 59 #endif//SkDynamicAnnotations_DEFINED | |
| OLD | NEW |