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

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

Issue 2425683003: Change RefCountedObject to use perfect forwarding. (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 side-by-side diff with in-line comments
Download patch
Index: webrtc/base/refcount.h.pump
diff --git a/webrtc/base/refcount.h.pump b/webrtc/base/refcount.h.pump
new file mode 100644
index 0000000000000000000000000000000000000000..cbf32f5ca6784b4e9eb7ded505eb194ad603399c
--- /dev/null
+++ b/webrtc/base/refcount.h.pump
@@ -0,0 +1,76 @@
+/*
+ * Copyright 2011 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/refcount.h.pump
+
+#ifndef WEBRTC_BASE_REFCOUNT_H_
+#define WEBRTC_BASE_REFCOUNT_H_
+
+#include <string.h>
+#include <utility>
+
+#include "webrtc/base/atomicops.h"
+
+namespace rtc {
+
+// Reference count interface.
+class RefCountInterface {
tommi 2016/10/18 15:57:58 Can we have this definition in a non-generated hea
perkj_webrtc 2016/10/19 00:43:14 Done.
+ public:
+ virtual int AddRef() const = 0;
+ virtual int Release() const = 0;
+
+ protected:
+ virtual ~RefCountInterface() {}
+};
+
+
+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_REFCOUNT_H_

Powered by Google App Engine
This is Rietveld 408576698