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

Side by Side Diff: src/core/SkSharedMutex.cpp

Issue 2293063002: Detect TSAN instead of relying on #ifdef THREAD_SANITIZER. (Closed)
Patch Set: Created 4 years, 3 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 | « gyp/common_conditions.gypi ('k') | no next file » | 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 2015 Google Inc. 2 * Copyright 2015 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 #include "SkSharedMutex.h" 8 #include "SkSharedMutex.h"
9 9
10 #include "SkAtomics.h" 10 #include "SkAtomics.h"
11 #include "SkTypes.h" 11 #include "SkTypes.h"
12 #include "SkSemaphore.h" 12 #include "SkSemaphore.h"
13 13
14 #if defined(THREAD_SANITIZER) 14 #if !defined(__has_feature)
15 15 #define __has_feature(x) 0
16 /* Report that a lock has been created at address "lock". */
17 #define ANNOTATE_RWLOCK_CREATE(lock) \
18 AnnotateRWLockCreate(__FILE__, __LINE__, lock)
19
20 /* Report that the lock at address "lock" is about to be destroyed. */
21 #define ANNOTATE_RWLOCK_DESTROY(lock) \
22 AnnotateRWLockDestroy(__FILE__, __LINE__, lock)
23
24 /* Report that the lock at address "lock" has been acquired.
25 is_w=1 for writer lock, is_w=0 for reader lock. */
26 #define ANNOTATE_RWLOCK_ACQUIRED(lock, is_w) \
27 AnnotateRWLockAcquired(__FILE__, __LINE__, lock, is_w)
28
29 /* Report that the lock at address "lock" is about to be released. */
30 #define ANNOTATE_RWLOCK_RELEASED(lock, is_w) \
31 AnnotateRWLockReleased(__FILE__, __LINE__, lock, is_w)
32
33 #ifdef DYNAMIC_ANNOTATIONS_WANT_ATTRIBUTE_WEAK
34 # ifdef __GNUC__
35 # define DYNAMIC_ANNOTATIONS_ATTRIBUTE_WEAK __attribute__((weak))
36 # else
37 /* TODO(glider): for Windows support we may want to change this macro in order
38 to prepend __declspec(selectany) to the annotations' declarations. */
39 # error weak annotations are not supported for your compiler
40 # endif
41 #else
42 # define DYNAMIC_ANNOTATIONS_ATTRIBUTE_WEAK
43 #endif 16 #endif
44 17
45 extern "C" { 18 #if __has_feature(thread_sanitizer)
46 void AnnotateRWLockCreate( 19
47 const char *file, int line, 20 /* Report that a lock has been created at address "lock". */
48 const volatile void *lock) DYNAMIC_ANNOTATIONS_ATTRIBUTE_WEAK; 21 #define ANNOTATE_RWLOCK_CREATE(lock) \
49 void AnnotateRWLockDestroy( 22 AnnotateRWLockCreate(__FILE__, __LINE__, lock)
50 const char *file, int line, 23
51 const volatile void *lock) DYNAMIC_ANNOTATIONS_ATTRIBUTE_WEAK; 24 /* Report that the lock at address "lock" is about to be destroyed. */
52 void AnnotateRWLockAcquired( 25 #define ANNOTATE_RWLOCK_DESTROY(lock) \
53 const char *file, int line, 26 AnnotateRWLockDestroy(__FILE__, __LINE__, lock)
54 const volatile void *lock, long is_w) DYNAMIC_ANNOTATIONS_ATTRIBUTE_WEAK; 27
55 void AnnotateRWLockReleased( 28 /* Report that the lock at address "lock" has been acquired.
56 const char *file, int line, 29 is_w=1 for writer lock, is_w=0 for reader lock. */
57 const volatile void *lock, long is_w) DYNAMIC_ANNOTATIONS_ATTRIBUTE_WEAK; 30 #define ANNOTATE_RWLOCK_ACQUIRED(lock, is_w) \
58 } 31 AnnotateRWLockAcquired(__FILE__, __LINE__, lock, is_w)
32
33 /* Report that the lock at address "lock" is about to be released. */
34 #define ANNOTATE_RWLOCK_RELEASED(lock, is_w) \
35 AnnotateRWLockReleased(__FILE__, __LINE__, lock, is_w)
36
37 #if defined(DYNAMIC_ANNOTATIONS_WANT_ATTRIBUTE_WEAK)
38 #if defined(__GNUC__)
39 #define DYNAMIC_ANNOTATIONS_ATTRIBUTE_WEAK __attribute__((weak))
40 #else
41 /* TODO(glider): for Windows support we may want to change this macr o in order
42 to prepend __declspec(selectany) to the annotations' declarations . */
43 #error weak annotations are not supported for your compiler
44 #endif
45 #else
46 #define DYNAMIC_ANNOTATIONS_ATTRIBUTE_WEAK
47 #endif
48
49 extern "C" {
50 void AnnotateRWLockCreate(
51 const char *file, int line,
52 const volatile void *lock) DYNAMIC_ANNOTATIONS_ATTRIBUTE_WEAK;
53 void AnnotateRWLockDestroy(
54 const char *file, int line,
55 const volatile void *lock) DYNAMIC_ANNOTATIONS_ATTRIBUTE_WEAK;
56 void AnnotateRWLockAcquired(
57 const char *file, int line,
58 const volatile void *lock, long is_w) DYNAMIC_ANNOTATIONS_ATTRIBUTE_WEAK ;
59 void AnnotateRWLockReleased(
60 const char *file, int line,
61 const volatile void *lock, long is_w) DYNAMIC_ANNOTATIONS_ATTRIBUTE_WEAK ;
62 }
59 63
60 #else 64 #else
61 65
62 #define ANNOTATE_RWLOCK_CREATE(lock) 66 #define ANNOTATE_RWLOCK_CREATE(lock)
63 #define ANNOTATE_RWLOCK_DESTROY(lock) 67 #define ANNOTATE_RWLOCK_DESTROY(lock)
64 #define ANNOTATE_RWLOCK_ACQUIRED(lock, is_w) 68 #define ANNOTATE_RWLOCK_ACQUIRED(lock, is_w)
65 #define ANNOTATE_RWLOCK_RELEASED(lock, is_w) 69 #define ANNOTATE_RWLOCK_RELEASED(lock, is_w)
66 70
67 #endif 71 #endif
68 72
69 #ifdef SK_DEBUG 73 #ifdef SK_DEBUG
70 74
71 #include "SkThreadID.h" 75 #include "SkThreadID.h"
72 #include "SkTDArray.h" 76 #include "SkTDArray.h"
73 77
74 class SkSharedMutex::ThreadIDSet { 78 class SkSharedMutex::ThreadIDSet {
75 public: 79 public:
(...skipping 265 matching lines...) Expand 10 before | Expand all | Expand 10 after
341 345
342 // If shared count is going to zero (because the old count == 1) and the re are exclusive 346 // If shared count is going to zero (because the old count == 1) and the re are exclusive
343 // waiters, then run a single exclusive waiter. 347 // waiters, then run a single exclusive waiter.
344 if (((oldQueueCounts & kSharedMask) >> kSharedOffset) == 1 348 if (((oldQueueCounts & kSharedMask) >> kSharedOffset) == 1
345 && (oldQueueCounts & kWaitingExclusiveMask) > 0) { 349 && (oldQueueCounts & kWaitingExclusiveMask) > 0) {
346 fExclusiveQueue.signal(); 350 fExclusiveQueue.signal();
347 } 351 }
348 } 352 }
349 353
350 #endif 354 #endif
OLDNEW
« no previous file with comments | « gyp/common_conditions.gypi ('k') | no next file » | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698