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

Side by Side Diff: webrtc/base/refcount.h

Issue 1505053002: Revert of "Create rtc::AtomicInt POD struct." (Closed) Base URL: https://chromium.googlesource.com/external/webrtc.git@master
Patch Set: Created 5 years 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
OLDNEW
1 /* 1 /*
2 * Copyright 2011 The WebRTC Project Authors. All rights reserved. 2 * Copyright 2011 The WebRTC Project Authors. All rights reserved.
3 * 3 *
4 * Use of this source code is governed by a BSD-style license 4 * Use of this source code is governed by a BSD-style license
5 * that can be found in the LICENSE file in the root of the source 5 * that can be found in the LICENSE file in the root of the source
6 * tree. An additional intellectual property rights grant can be found 6 * tree. An additional intellectual property rights grant can be found
7 * in the file PATENTS. All contributing project authors may 7 * in the file PATENTS. All contributing project authors may
8 * be found in the AUTHORS file in the root of the source tree. 8 * be found in the AUTHORS file in the root of the source tree.
9 */ 9 */
10 10
(...skipping 11 matching lines...) Expand all
22 public: 22 public:
23 virtual int AddRef() const = 0; 23 virtual int AddRef() const = 0;
24 virtual int Release() const = 0; 24 virtual int Release() const = 0;
25 protected: 25 protected:
26 virtual ~RefCountInterface() {} 26 virtual ~RefCountInterface() {}
27 }; 27 };
28 28
29 template <class T> 29 template <class T>
30 class RefCountedObject : public T { 30 class RefCountedObject : public T {
31 public: 31 public:
32 RefCountedObject() : ref_count_({0}) {} 32 RefCountedObject() : ref_count_(0) {
33 }
33 34
34 template <typename P> 35 template<typename P>
35 explicit RefCountedObject(P p) 36 explicit RefCountedObject(P p) : T(p), ref_count_(0) {
36 : T(p), ref_count_({0}) {} 37 }
37 38
38 template <typename P1, typename P2> 39 template<typename P1, typename P2>
39 RefCountedObject(P1 p1, P2 p2) 40 RefCountedObject(P1 p1, P2 p2) : T(p1, p2), ref_count_(0) {
40 : T(p1, p2), ref_count_({0}) {} 41 }
41 42
42 template <typename P1, typename P2, typename P3> 43 template<typename P1, typename P2, typename P3>
43 RefCountedObject(P1 p1, P2 p2, P3 p3) 44 RefCountedObject(P1 p1, P2 p2, P3 p3) : T(p1, p2, p3), ref_count_(0) {
44 : T(p1, p2, p3), ref_count_({0}) {} 45 }
45 46
46 template <typename P1, typename P2, typename P3, typename P4> 47 template<typename P1, typename P2, typename P3, typename P4>
47 RefCountedObject(P1 p1, P2 p2, P3 p3, P4 p4) 48 RefCountedObject(P1 p1, P2 p2, P3 p3, P4 p4)
48 : T(p1, p2, p3, p4), ref_count_({0}) {} 49 : T(p1, p2, p3, p4), ref_count_(0) {
50 }
49 51
50 template <typename P1, typename P2, typename P3, typename P4, typename P5> 52 template<typename P1, typename P2, typename P3, typename P4, typename P5>
51 RefCountedObject(P1 p1, P2 p2, P3 p3, P4 p4, P5 p5) 53 RefCountedObject(P1 p1, P2 p2, P3 p3, P4 p4, P5 p5)
52 : T(p1, p2, p3, p4, p5), ref_count_({0}) {} 54 : T(p1, p2, p3, p4, p5), ref_count_(0) {
55 }
53 56
54 template <typename P1, 57 template<typename P1, typename P2, typename P3, typename P4, typename P5,
55 typename P2, 58 typename P6>
56 typename P3,
57 typename P4,
58 typename P5,
59 typename P6>
60 RefCountedObject(P1 p1, P2 p2, P3 p3, P4 p4, P5 p5, P6 p6) 59 RefCountedObject(P1 p1, P2 p2, P3 p3, P4 p4, P5 p5, P6 p6)
61 : T(p1, p2, p3, p4, p5, p6), ref_count_({0}) {} 60 : T(p1, p2, p3, p4, p5, p6), ref_count_(0) {
61 }
62 62
63 template <typename P1, 63 template<typename P1, typename P2, typename P3, typename P4, typename P5,
64 typename P2, 64 typename P6, typename P7>
65 typename P3,
66 typename P4,
67 typename P5,
68 typename P6,
69 typename P7>
70 RefCountedObject(P1 p1, P2 p2, P3 p3, P4 p4, P5 p5, P6 p6, P7 p7) 65 RefCountedObject(P1 p1, P2 p2, P3 p3, P4 p4, P5 p5, P6 p6, P7 p7)
71 : T(p1, p2, p3, p4, p5, p6, p7), ref_count_({0}) {} 66 : T(p1, p2, p3, p4, p5, p6, p7), ref_count_(0) {
67 }
72 68
73 template <typename P1, 69 template<typename P1, typename P2, typename P3, typename P4, typename P5,
74 typename P2, 70 typename P6, typename P7, typename P8>
75 typename P3,
76 typename P4,
77 typename P5,
78 typename P6,
79 typename P7,
80 typename P8>
81 RefCountedObject(P1 p1, P2 p2, P3 p3, P4 p4, P5 p5, P6 p6, P7 p7, P8 p8) 71 RefCountedObject(P1 p1, P2 p2, P3 p3, P4 p4, P5 p5, P6 p6, P7 p7, P8 p8)
82 : T(p1, p2, p3, p4, p5, p6, p7, p8), ref_count_({0}) {} 72 : T(p1, p2, p3, p4, p5, p6, p7, p8), ref_count_(0) {
73 }
83 74
84 template <typename P1, 75 template<typename P1, typename P2, typename P3, typename P4, typename P5,
85 typename P2, 76 typename P6, typename P7, typename P8, typename P9>
86 typename P3, 77 RefCountedObject(
87 typename P4, 78 P1 p1, P2 p2, P3 p3, P4 p4, P5 p5, P6 p6, P7 p7, P8 p8, P9 p9)
88 typename P5, 79 : T(p1, p2, p3, p4, p5, p6, p7, p8, p9), ref_count_(0) {
89 typename P6, 80 }
90 typename P7,
91 typename P8,
92 typename P9>
93 RefCountedObject(P1 p1,
94 P2 p2,
95 P3 p3,
96 P4 p4,
97 P5 p5,
98 P6 p6,
99 P7 p7,
100 P8 p8,
101 P9 p9)
102 : T(p1, p2, p3, p4, p5, p6, p7, p8, p9), ref_count_({0}) {}
103 81
104 template <typename P1, 82 template<typename P1, typename P2, typename P3, typename P4, typename P5,
105 typename P2, 83 typename P6, typename P7, typename P8, typename P9, typename P10>
106 typename P3, 84 RefCountedObject(
107 typename P4, 85 P1 p1, P2 p2, P3 p3, P4 p4, P5 p5, P6 p6, P7 p7, P8 p8, P9 p9, P10 p10)
108 typename P5, 86 : T(p1, p2, p3, p4, p5, p6, p7, p8, p9, p10), ref_count_(0) {
109 typename P6, 87 }
110 typename P7,
111 typename P8,
112 typename P9,
113 typename P10>
114 RefCountedObject(P1 p1,
115 P2 p2,
116 P3 p3,
117 P4 p4,
118 P5 p5,
119 P6 p6,
120 P7 p7,
121 P8 p8,
122 P9 p9,
123 P10 p10)
124 : T(p1, p2, p3, p4, p5, p6, p7, p8, p9, p10), ref_count_({0}) {}
125 88
126 template <typename P1, 89 template<typename P1, typename P2, typename P3, typename P4, typename P5,
127 typename P2, 90 typename P6, typename P7, typename P8, typename P9, typename P10,
128 typename P3, 91 typename P11>
129 typename P4, 92 RefCountedObject(
130 typename P5, 93 P1 p1, P2 p2, P3 p3, P4 p4, P5 p5, P6 p6, P7 p7, P8 p8, P9 p9, P10 p10,
131 typename P6, 94 P11 p11)
132 typename P7, 95 : T(p1, p2, p3, p4, p5, p6, p7, p8, p9, p10, p11), ref_count_(0) {
133 typename P8, 96 }
134 typename P9,
135 typename P10,
136 typename P11>
137 RefCountedObject(P1 p1,
138 P2 p2,
139 P3 p3,
140 P4 p4,
141 P5 p5,
142 P6 p6,
143 P7 p7,
144 P8 p8,
145 P9 p9,
146 P10 p10,
147 P11 p11)
148 : T(p1, p2, p3, p4, p5, p6, p7, p8, p9, p10, p11), ref_count_({0}) {}
149 97
150 virtual int AddRef() const { return AtomicInt::Increment(&ref_count_); } 98 virtual int AddRef() const {
99 return AtomicOps::Increment(&ref_count_);
100 }
151 101
152 virtual int Release() const { 102 virtual int Release() const {
153 int count = AtomicInt::Decrement(&ref_count_); 103 int count = AtomicOps::Decrement(&ref_count_);
154 if (!count) { 104 if (!count) {
155 delete this; 105 delete this;
156 } 106 }
157 return count; 107 return count;
158 } 108 }
159 109
160 // Return whether the reference count is one. If the reference count is used 110 // Return whether the reference count is one. If the reference count is used
161 // in the conventional way, a reference count of 1 implies that the current 111 // in the conventional way, a reference count of 1 implies that the current
162 // thread owns the reference and no other thread shares it. This call 112 // thread owns the reference and no other thread shares it. This call
163 // performs the test for a reference count of one, and performs the memory 113 // performs the test for a reference count of one, and performs the memory
164 // barrier needed for the owning thread to act on the object, knowing that it 114 // barrier needed for the owning thread to act on the object, knowing that it
165 // has exclusive access to the object. 115 // has exclusive access to the object.
166 virtual bool HasOneRef() const { 116 virtual bool HasOneRef() const {
167 return AtomicInt::AcquireLoad(&ref_count_) == 1; 117 return AtomicOps::AcquireLoad(&ref_count_) == 1;
168 } 118 }
169 119
170 protected: 120 protected:
171 virtual ~RefCountedObject() { 121 virtual ~RefCountedObject() {
172 } 122 }
173 123
174 mutable AtomicInt ref_count_; 124 mutable volatile int ref_count_;
175 }; 125 };
176 126
177 } // namespace rtc 127 } // namespace rtc
178 128
179 #endif // WEBRTC_BASE_REFCOUNT_H_ 129 #endif // WEBRTC_BASE_REFCOUNT_H_
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698