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

Side by Side Diff: webrtc/base/refcountedobject.h.pump

Issue 2438013003: Use variadic templates instead of pump for RefCountedObject (Closed)
Patch Set: Created 4 years, 2 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 | « webrtc/base/refcountedobject.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 /*
2 * Copyright 2016 The WebRTC Project Authors. All rights reserved.
3 *
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
6 * tree. An additional intellectual property rights grant can be found
7 * in the file PATENTS. All contributing project authors may
8 * be found in the AUTHORS file in the root of the source tree.
9 */
10
11 // To generate refcount.h from refcount.h.pump, execute:
12 // ./testing/gtest/scripts/pump.py ./webrtc/base/refcountedobject.h.pump
13
14 #ifndef WEBRTC_BASE_REFCOUNTEDOBJECT_H_
15 #define WEBRTC_BASE_REFCOUNTEDOBJECT_H_
16
17 #include <utility>
18
19 #include "webrtc/base/atomicops.h"
20
21 namespace rtc {
22
23 template <class T>
24 class RefCountedObject : public T {
25 public:
26 RefCountedObject() {}
27
28 $range i 0..10
29 $for i [[
30 $range j 0..i
31 template <$for j , [[class P$j]]>
32 $if i == 0 [[explicit ]]
33 RefCountedObject($for j , [[P$j&& p$j]]) : T($for j , [[std::forward<P$j>(p$j) ]]) {}
34 ]]
35
36 virtual int AddRef() const { return AtomicOps::Increment(&ref_count_); }
37
38 virtual int Release() const {
39 int count = AtomicOps::Decrement(&ref_count_);
40 if (!count) {
41 delete this;
42 }
43 return count;
44 }
45
46 // Return whether the reference count is one. If the reference count is used
47 // in the conventional way, a reference count of 1 implies that the current
48 // thread owns the reference and no other thread shares it. This call
49 // performs the test for a reference count of one, and performs the memory
50 // barrier needed for the owning thread to act on the object, knowing that it
51 // has exclusive access to the object.
52 virtual bool HasOneRef() const {
53 return AtomicOps::AcquireLoad(&ref_count_) == 1;
54 }
55
56 protected:
57 virtual ~RefCountedObject() {}
58
59 mutable volatile int ref_count_ = 0;
60 };
61
62 } // namespace rtc
63
64 #endif // WEBRTC_BASE_REFCOUNTEDOBJECT_H_
OLDNEW
« no previous file with comments | « webrtc/base/refcountedobject.h ('k') | no next file » | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698