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

Unified Diff: webrtc/base/refcountedobject.h.pump

Issue 2425683003: Change RefCountedObject to use perfect forwarding. (Closed)
Patch Set: git cl lint + screen_capturer_differ_wrapper.cc 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 side-by-side diff with in-line comments
Download patch
« no previous file with comments | « webrtc/base/refcountedobject.h ('k') | webrtc/base/refcountedobject_unittest.cc » ('j') | no next file with comments »
Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
Index: webrtc/base/refcountedobject.h.pump
diff --git a/webrtc/base/refcountedobject.h.pump b/webrtc/base/refcountedobject.h.pump
new file mode 100644
index 0000000000000000000000000000000000000000..cbf54e5b58d39bf03f459966829ecc074e300d2c
--- /dev/null
+++ b/webrtc/base/refcountedobject.h.pump
@@ -0,0 +1,64 @@
+/*
+ * Copyright 2016 The WebRTC Project Authors. All rights reserved.
+ *
+ * Use of this source code is governed by a BSD-style license
+ * that can be found in the LICENSE file in the root of the source
+ * tree. An additional intellectual property rights grant can be found
+ * in the file PATENTS. All contributing project authors may
+ * be found in the AUTHORS file in the root of the source tree.
+ */
+
+// To generate refcount.h from refcount.h.pump, execute:
+// ./testing/gtest/scripts/pump.py ./webrtc/base/refcountedobject.h.pump
+
+#ifndef WEBRTC_BASE_REFCOUNTEDOBJECT_H_
+#define WEBRTC_BASE_REFCOUNTEDOBJECT_H_
+
+#include <utility>
+
+#include "webrtc/base/atomicops.h"
+
+namespace rtc {
+
+template <class T>
+class RefCountedObject : public T {
+ public:
+ RefCountedObject() {}
+
+ $range i 0..10
+ $for i [[
+ $range j 0..i
+ template <$for j , [[class P$j]]>
+ $if i == 0 [[explicit ]]
+ RefCountedObject($for j , [[P$j&& p$j]]) : T($for j , [[std::forward<P$j>(p$j)]]) {}
+ ]]
+
+ virtual int AddRef() const { return AtomicOps::Increment(&ref_count_); }
+
+ virtual int Release() const {
+ int count = AtomicOps::Decrement(&ref_count_);
+ if (!count) {
+ delete this;
+ }
+ return count;
+ }
+
+ // Return whether the reference count is one. If the reference count is used
+ // in the conventional way, a reference count of 1 implies that the current
+ // thread owns the reference and no other thread shares it. This call
+ // performs the test for a reference count of one, and performs the memory
+ // barrier needed for the owning thread to act on the object, knowing that it
+ // has exclusive access to the object.
+ virtual bool HasOneRef() const {
+ return AtomicOps::AcquireLoad(&ref_count_) == 1;
+ }
+
+ protected:
+ virtual ~RefCountedObject() {}
+
+ mutable volatile int ref_count_ = 0;
+};
+
+} // namespace rtc
+
+#endif // WEBRTC_BASE_REFCOUNTEDOBJECT_H_
« no previous file with comments | « webrtc/base/refcountedobject.h ('k') | webrtc/base/refcountedobject_unittest.cc » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698