Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(72)

Side by Side Diff: include/core/SkDynamicAnnotations.h

Issue 247813005: teach TSAN about SkSpinlock, SkRefCnt, and SkOnce (Closed) Base URL: https://skia.googlesource.com/skia.git@master
Patch Set: undo Created 6 years, 7 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch
« no previous file with comments | « no previous file | include/core/SkOnce.h » ('j') | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
OLDNEW
1 /* 1 /*
2 * Copyright 2014 Google Inc. 2 * Copyright 2014 Google Inc.
3 * 3 *
4 * Use of this source code is governed by a BSD-style license that can be 4 * Use of this source code is governed by a BSD-style license that can be
5 * found in the LICENSE file. 5 * found in the LICENSE file.
6 */ 6 */
7 7
8 #ifndef SkDynamicAnnotations_DEFINED 8 #ifndef SkDynamicAnnotations_DEFINED
9 #define SkDynamicAnnotations_DEFINED 9 #define SkDynamicAnnotations_DEFINED
10 10
11 // This file contains macros used to send out-of-band signals to dynamic instrum entation systems, 11 // This file contains macros used to send out-of-band signals to dynamic instrum entation systems,
12 // namely thread sanitizer. This is a cut-down version of the full dynamic_anno tations library with 12 // namely thread sanitizer. This is a cut-down version of the full dynamic_anno tations library with
13 // only the features used by Skia. 13 // only the features used by Skia.
14 14
15 // We check the same define to know to enable the annotations, but prefix all ou r macros with SK_. 15 // We check the same define to know to enable the annotations, but prefix all ou r macros with SK_.
16 #if DYNAMIC_ANNOTATIONS_ENABLED 16 #if DYNAMIC_ANNOTATIONS_ENABLED
17 17
18 extern "C" { 18 extern "C" {
19 // TSAN provides these hooks. 19 // TSAN provides these hooks.
20 void AnnotateIgnoreReadsBegin(const char* file, int line); 20 void AnnotateIgnoreReadsBegin(const char* file, int line);
21 void AnnotateIgnoreReadsEnd(const char* file, int line); 21 void AnnotateIgnoreReadsEnd(const char* file, int line);
22 void AnnotateHappensBefore(const char* file, int line, const volatile void* ptr) ;
23 void AnnotateHappensAfter(const char* file, int line, const volatile void* ptr);
24 void AnnotateRWLockAcquired(const char* file, int line, const volatile void* loc k, long is_w);
25 void AnnotateRWLockReleased(const char* file, int line, const volatile void* loc k, long is_w);
26 } // extern "C" 22 } // extern "C"
27 23
28 // SK_ANNOTATE_UNPROTECTED_READ can wrap any variable read to tell TSAN to ignor e that it appears to 24 // 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 25 // 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: 26 // 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; 27 // - the first check in double-checked locking;
32 // - checking if a ref count is equal to 1. 28 // - 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 29 // 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 30 // 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. 31 // external guarantee is pretty much never correct.
36 template <typename T> 32 template <typename T>
37 inline T SK_ANNOTATE_UNPROTECTED_READ(const volatile T& x) { 33 inline T SK_ANNOTATE_UNPROTECTED_READ(const volatile T& x) {
38 AnnotateIgnoreReadsBegin(__FILE__, __LINE__); 34 AnnotateIgnoreReadsBegin(__FILE__, __LINE__);
39 T read = x; 35 T read = x;
40 AnnotateIgnoreReadsEnd(__FILE__, __LINE__); 36 AnnotateIgnoreReadsEnd(__FILE__, __LINE__);
41 return read; 37 return read;
42 } 38 }
43 39
44 #define SK_ANNOTATE_HAPPENS_BEFORE(obj) AnnotateHappensBefore(__FILE__, __LINE__ , obj)
45 #define SK_ANNOTATE_HAPPENS_AFTER(obj) AnnotateHappensAfter(__FILE__, __LINE__, obj)
46
47 #define SK_ANNOTATE_RWLOCK_ACQUIRED(lock, w) AnnotateRWLockAcquired(__FILE__, __ LINE__, lock, w)
48 #define SK_ANNOTATE_RWLOCK_RELEASED(lock, w) AnnotateRWLockReleased(__FILE__, __ LINE__, lock, w)
49
50 #else // !DYNAMIC_ANNOTATIONS_ENABLED 40 #else // !DYNAMIC_ANNOTATIONS_ENABLED
51 41
52 #define SK_ANNOTATE_UNPROTECTED_READ(x) (x) 42 #define SK_ANNOTATE_UNPROTECTED_READ(x) (x)
53 #define SK_ANNOTATE_HAPPENS_BEFORE(obj)
54 #define SK_ANNOTATE_HAPPENS_AFTER(obj)
55 #define SK_ANNOTATE_RWLOCK_ACQUIRED(lock, w)
56 #define SK_ANNOTATE_RWLOCK_RELEASED(lock, w)
57 43
58 #endif 44 #endif
59 45
60 #endif//SkDynamicAnnotations_DEFINED 46 #endif//SkDynamicAnnotations_DEFINED
OLDNEW
« no previous file with comments | « no previous file | include/core/SkOnce.h » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698