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

Side by Side Diff: base/memory/ref_counted.cc

Issue 2345013003: Remove ref_counted.cc (Closed)
Patch Set: revert _EXPORT part 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 | « base/memory/ref_counted.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
(Empty)
1 // Copyright (c) 2011 The Chromium Authors. All rights reserved.
2 // Use of this source code is governed by a BSD-style license that can be
3 // found in the LICENSE file.
4
5 #include "base/memory/ref_counted.h"
6 #include "base/threading/thread_collision_warner.h"
7
8 namespace base {
9
10 namespace subtle {
11
12 bool RefCountedThreadSafeBase::HasOneRef() const {
13 return AtomicRefCountIsOne(
14 &const_cast<RefCountedThreadSafeBase*>(this)->ref_count_);
15 }
16
17 RefCountedThreadSafeBase::RefCountedThreadSafeBase() : ref_count_(0) {
18 #ifndef NDEBUG
19 in_dtor_ = false;
20 #endif
21 }
22
23 RefCountedThreadSafeBase::~RefCountedThreadSafeBase() {
24 #ifndef NDEBUG
25 DCHECK(in_dtor_) << "RefCountedThreadSafe object deleted without "
26 "calling Release()";
27 #endif
28 }
29
30 void RefCountedThreadSafeBase::AddRef() const {
31 #ifndef NDEBUG
32 DCHECK(!in_dtor_);
33 #endif
34 AtomicRefCountInc(&ref_count_);
35 }
36
37 bool RefCountedThreadSafeBase::Release() const {
38 #ifndef NDEBUG
39 DCHECK(!in_dtor_);
40 DCHECK(!AtomicRefCountIsZero(&ref_count_));
41 #endif
42 if (!AtomicRefCountDec(&ref_count_)) {
43 #ifndef NDEBUG
44 in_dtor_ = true;
45 #endif
46 return true;
47 }
48 return false;
49 }
50
51 } // namespace subtle
52
53 } // namespace base
OLDNEW
« no previous file with comments | « base/memory/ref_counted.h ('k') | no next file » | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698