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

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

Issue 144953005: TSAN: use somewhat pithier SK_ANNOTATE_UNPROTECTED_READ. (Closed) Base URL: https://skia.googlesource.com/skia.git@master
Patch Set: benh Created 6 years, 10 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 | « include/core/SkOnce.h ('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 /* 2 /*
3 * Copyright 2006 The Android Open Source Project 3 * Copyright 2006 The Android Open Source Project
4 * 4 *
5 * Use of this source code is governed by a BSD-style license that can be 5 * Use of this source code is governed by a BSD-style license that can be
6 * found in the LICENSE file. 6 * found in the LICENSE file.
7 */ 7 */
8 8
9 9
10 #ifndef SkRefCnt_DEFINED 10 #ifndef SkRefCnt_DEFINED
11 #define SkRefCnt_DEFINED 11 #define SkRefCnt_DEFINED
12 12
13 #include "SkDynamicAnnotations.h"
13 #include "SkThread.h" 14 #include "SkThread.h"
14 #include "SkInstCnt.h" 15 #include "SkInstCnt.h"
15 #include "SkTemplates.h" 16 #include "SkTemplates.h"
16 17
17 /** \class SkRefCntBase 18 /** \class SkRefCntBase
18 19
19 SkRefCntBase is the base class for objects that may be shared by multiple 20 SkRefCntBase is the base class for objects that may be shared by multiple
20 objects. When an existing owner wants to share a reference, it calls ref(). 21 objects. When an existing owner wants to share a reference, it calls ref().
21 When an owner wants to release its reference, it calls unref(). When the 22 When an owner wants to release its reference, it calls unref(). When the
22 shared object's reference count goes to zero as the result of an unref() 23 shared object's reference count goes to zero as the result of an unref()
(...skipping 14 matching lines...) Expand all
37 virtual ~SkRefCntBase() { 38 virtual ~SkRefCntBase() {
38 #ifdef SK_DEBUG 39 #ifdef SK_DEBUG
39 SkASSERT(fRefCnt == 1); 40 SkASSERT(fRefCnt == 1);
40 fRefCnt = 0; // illegal value, to catch us if we reuse after delete 41 fRefCnt = 0; // illegal value, to catch us if we reuse after delete
41 #endif 42 #endif
42 } 43 }
43 44
44 /** Return the reference count. Use only for debugging. */ 45 /** Return the reference count. Use only for debugging. */
45 int32_t getRefCnt() const { return fRefCnt; } 46 int32_t getRefCnt() const { return fRefCnt; }
46 47
47 /** Returns true if the caller is the only owner. 48 /** May return true if the caller is the only owner.
48 * Ensures that all previous owner's actions are complete. 49 * Ensures that all previous owner's actions are complete.
49 */ 50 */
50 bool unique() const { 51 bool unique() const {
51 bool const unique = (1 == fRefCnt); 52 // We believe we're reading fRefCnt in a safe way here, so we stifle the TSAN warning about
53 // an unproctected read. Generally, don't read fRefCnt, and don't stifl e this warning.
bungeman-skia 2014/02/04 17:21:39 nit: two spaces after the period.
54 bool const unique = (1 == SK_ANNOTATE_UNPROTECTED_READ(fRefCnt));
52 if (unique) { 55 if (unique) {
53 // Acquire barrier (L/SL), if not provided by load of fRefCnt. 56 // Acquire barrier (L/SL), if not provided by load of fRefCnt.
54 // Prevents user's 'unique' code from happening before decrements. 57 // Prevents user's 'unique' code from happening before decrements.
55 //TODO: issue the barrier. 58 //TODO: issue the barrier.
56 } 59 }
57 return unique; 60 return unique;
58 } 61 }
59 62
60 /** Increment the reference count. Must be balanced by a call to unref(). 63 /** Increment the reference count. Must be balanced by a call to unref().
61 */ 64 */
(...skipping 218 matching lines...) Expand 10 before | Expand all | Expand 10 after
280 typedef T* SkRefPtr::*unspecified_bool_type; 283 typedef T* SkRefPtr::*unspecified_bool_type;
281 operator unspecified_bool_type() const { 284 operator unspecified_bool_type() const {
282 return fObj ? &SkRefPtr::fObj : NULL; 285 return fObj ? &SkRefPtr::fObj : NULL;
283 } 286 }
284 287
285 private: 288 private:
286 T* fObj; 289 T* fObj;
287 }; 290 };
288 291
289 #endif 292 #endif
OLDNEW
« no previous file with comments | « include/core/SkOnce.h ('k') | no next file » | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698