Reland of Delete rtc::linked_ptr. (patchset #1 id:1 of https://codereview.webrtc.org/2579753002/ )
Only use, in statstypes.h, replaced by rtc::scoped_refptr.
Reason for revert:
Intend to switch from unique_ptr to scoped_refptr,
and then reland.
Original issue's description:
> Revert of Delete rtc::linked_ptr. Only use, in statstypes.h, replaced bu std::unique_ptr. (patchset #1 id:1 of https://codereview.webrtc.org/2581663002/ )
>
> Reason for revert:
> This change broke Chrome too. It's stats processing wants to make a copy of webrtc's stats mapping, which is no longer possible with std::unique_ptr.
>
> Original issue's description:
> > Reland of Delete rtc::linked_ptr. Only use, in statstypes.h, replaced bu std::unique_ptr. (patchset #1 id:1 of https://codereview.webrtc.org/2576673002/ )
> >
> > Reason for revert:
> > Downstream project fixed to not make copies while iterating over the stats mapping.
> >
> > Original issue's description:
> > > Revert of Delete rtc::linked_ptr. Only use, in statstypes.h, replaced bu std::unique_ptr. (patchset #1 id:1 of https://codereview.webrtc.org/2567143003/ )
> > >
> > > Reason for revert:
> > > The change from rtc::linked_ptr to std::unique_ptr broke a downstream project.
> > >
> > > Original issue's description:
> > > > Delete rtc::linked_ptr. Only use, in statstypes.h, replaced with std::unique_ptr.
> > > >
> > > > BUG=webrtc:6424
> > > >
> > > > Committed: https://crrev.com/36f74e55792cae19db8b222c29aa38d6e0eb1225
> > > > Cr-Commit-Position: refs/heads/master@{#15588}
> > >
> > > TBR=solenberg@webrtc.org,pthatcher@webrtc.org,hta@webrtc.org
> > > # Skipping CQ checks because original CL landed less than 1 days ago.
> > > NOPRESUBMIT=true
> > > NOTREECHECKS=true
> > > NOTRY=true
> > > BUG=webrtc:6424
> > >
> > > Committed: https://crrev.com/8afbc8cba65d99bb7a0feece8fb3055b144106b1
> > > Cr-Commit-Position: refs/heads/master@{#15589}
> >
> > TBR=solenberg@webrtc.org,pthatcher@webrtc.org,hta@webrtc.org
> > # Not skipping CQ checks because original CL landed more than 1 days ago.
> > BUG=webrtc:6424
> >
> > Committed: https://crrev.com/06035cf53abad80b0525f286a3b81e388cc7ee00
> > Cr-Commit-Position: refs/heads/master@{#15627}
>
> TBR=solenberg@webrtc.org,pthatcher@webrtc.org,hta@webrtc.org
> # Skipping CQ checks because original CL landed less than 1 days ago.
> NOPRESUBMIT=true
> NOTREECHECKS=true
> NOTRY=true
> BUG=webrtc:6424
>
> Committed: https://crrev.com/6a58f33450a46370039cd82537612040a91165b3
> Cr-Commit-Position: refs/heads/master@{#15629}
TBR=solenberg@webrtc.org,pthatcher@webrtc.org,hta@webrtc.org
# Not skipping CQ checks because original CL landed more than 1 days ago.
BUG=webrtc:6424
Review-Url: https://codereview.webrtc.org/2641793002
Cr-Commit-Position: refs/heads/master@{#16148}
diff --git a/webrtc/api/statstypes.h b/webrtc/api/statstypes.h
index 1a55145..788c2c4 100644
--- a/webrtc/api/statstypes.h
+++ b/webrtc/api/statstypes.h
@@ -22,7 +22,6 @@
#include "webrtc/base/basictypes.h"
#include "webrtc/base/common.h"
#include "webrtc/base/constructormagic.h"
-#include "webrtc/base/linked_ptr.h"
#include "webrtc/base/refcount.h"
#include "webrtc/base/scoped_ref_ptr.h"
#include "webrtc/base/stringencode.h"
@@ -264,6 +263,22 @@
~Value();
+ // Support ref counting. Note that for performance reasons, we
+ // don't use thread safe operations. Therefore, all operations
+ // affecting the ref count (in practice, creation and copying of
+ // the Values mapping) must occur on webrtc's signalling thread.
+ int AddRef() const {
+ RTC_DCHECK_RUN_ON(&thread_checker_);
+ return ++ref_count_;
+ }
+ int Release() const {
+ RTC_DCHECK_RUN_ON(&thread_checker_);
+ int count = --ref_count_;
+ if (!count)
+ delete this;
+ return count;
+ }
+
// TODO(tommi): This compares name as well as value...
// I think we should only need to compare the value part and
// move the name part into a hash map.
@@ -304,6 +319,9 @@
const StatsValueName name;
private:
+ rtc::ThreadChecker thread_checker_;
+ mutable int ref_count_ ACCESS_ON(thread_checker_) = 0;
+
const Type type_;
// TODO(tommi): Use C++ 11 union and make value_ const.
union InternalType {
@@ -316,13 +334,10 @@
Id* id_;
} value_;
- private:
RTC_DISALLOW_COPY_AND_ASSIGN(Value);
};
- // TODO(tommi): Consider using a similar approach to how we store Ids using
- // scoped_refptr for values.
- typedef rtc::linked_ptr<Value> ValuePtr;
+ typedef rtc::scoped_refptr<Value> ValuePtr;
typedef std::map<StatsValueName, ValuePtr> Values;
// Ownership of |id| is passed to |this|.