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

Side by Side Diff: base/ref_counted.cc

Issue 6258: This CL is due the thread I have made on chromium-dev:... (Closed) Base URL: http://src.chromium.org/svn/trunk/src/
Patch Set: '' Created 12 years, 1 month 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 | Annotate | Revision Log
« no previous file with comments | « base/ref_counted.h ('k') | base/scoped_ptr.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 // Copyright (c) 2006-2008 The Chromium Authors. All rights reserved. 1 // Copyright (c) 2006-2008 The Chromium Authors. All rights reserved.
2 // Use of this source code is governed by a BSD-style license that can be 2 // Use of this source code is governed by a BSD-style license that can be
3 // found in the LICENSE file. 3 // found in the LICENSE file.
4 4
5 #include "base/ref_counted.h" 5 #include "base/ref_counted.h"
6 6
7 #include "base/logging.h" 7 #include "base/logging.h"
8 #include "base/thread_collision_warner.h"
8 9
9 namespace base { 10 namespace base {
10 11
11 namespace subtle { 12 namespace subtle {
12 13
13 RefCountedBase::RefCountedBase() : ref_count_(0) { 14 RefCountedBase::RefCountedBase() : ref_count_(0) {
14 #ifndef NDEBUG 15 #ifndef NDEBUG
15 in_dtor_ = false; 16 in_dtor_ = false;
16 #endif 17 #endif
17 } 18 }
18 19
19 RefCountedBase::~RefCountedBase() { 20 RefCountedBase::~RefCountedBase() {
20 #ifndef NDEBUG 21 #ifndef NDEBUG
21 DCHECK(in_dtor_) << "RefCounted object deleted without calling Release()"; 22 DCHECK(in_dtor_) << "RefCounted object deleted without calling Release()";
22 #endif 23 #endif
23 } 24 }
24 25
25 void RefCountedBase::AddRef() { 26 void RefCountedBase::AddRef() {
27 // Current thread books the critical section "AddRelease" without release it
28 D_BOOK_CRITICAL_SECTION(add_release_);
26 #ifndef NDEBUG 29 #ifndef NDEBUG
27 DCHECK(!in_dtor_); 30 DCHECK(!in_dtor_);
28 #endif 31 #endif
29 ++ref_count_; 32 ++ref_count_;
30 } 33 }
31 34
32 bool RefCountedBase::Release() { 35 bool RefCountedBase::Release() {
36 // Current thread books the critical section "AddRelease" without release it
37 D_BOOK_CRITICAL_SECTION(add_release_);
33 #ifndef NDEBUG 38 #ifndef NDEBUG
34 DCHECK(!in_dtor_); 39 DCHECK(!in_dtor_);
35 #endif 40 #endif
36 if (--ref_count_ == 0) { 41 if (--ref_count_ == 0) {
37 #ifndef NDEBUG 42 #ifndef NDEBUG
38 in_dtor_ = true; 43 in_dtor_ = true;
39 #endif 44 #endif
40 return true; 45 return true;
41 } 46 }
42 return false; 47 return false;
(...skipping 30 matching lines...) Expand all
73 #endif 78 #endif
74 return true; 79 return true;
75 } 80 }
76 return false; 81 return false;
77 } 82 }
78 83
79 } // namespace subtle 84 } // namespace subtle
80 85
81 } // namespace base 86 } // namespace base
82 87
OLDNEW
« no previous file with comments | « base/ref_counted.h ('k') | base/scoped_ptr.h » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698