summaryrefslogtreecommitdiffstats
path: root/base/ref_counted.h
diff options
context:
space:
mode:
authorajwong@chromium.org <ajwong@chromium.org@0039d316-1c4b-4281-b951-d872f2087c98>2011-02-14 20:51:18 +0000
committerajwong@chromium.org <ajwong@chromium.org@0039d316-1c4b-4281-b951-d872f2087c98>2011-02-14 20:51:18 +0000
commitfbbaad5f3cc19ff3cc06bcadb5390064d1a4b077 (patch)
tree28027947434db1cecbdb781b727b8b2252ca2cc9 /base/ref_counted.h
parentf258bbe05f0e0ff5580639ff1ede4b6f80a3bd58 (diff)
downloadchromium_src-fbbaad5f3cc19ff3cc06bcadb5390064d1a4b077.zip
chromium_src-fbbaad5f3cc19ff3cc06bcadb5390064d1a4b077.tar.gz
chromium_src-fbbaad5f3cc19ff3cc06bcadb5390064d1a4b077.tar.bz2
Redo "Add extra heap-allocation to refcounting. For perf test only."
Leaving it in tree for longer perf testing. Original review http://codereview.chromium.org/6484024/ BUG=none TEST=none Review URL: http://codereview.chromium.org/6517022 git-svn-id: svn://svn.chromium.org/chrome/trunk/src@74850 0039d316-1c4b-4281-b951-d872f2087c98
Diffstat (limited to 'base/ref_counted.h')
-rw-r--r--base/ref_counted.h17
1 files changed, 14 insertions, 3 deletions
diff --git a/base/ref_counted.h b/base/ref_counted.h
index 4c3aeb8..6a2b996 100644
--- a/base/ref_counted.h
+++ b/base/ref_counted.h
@@ -17,19 +17,25 @@ class RefCountedBase {
public:
static bool ImplementsThreadSafeReferenceCounting() { return false; }
- bool HasOneRef() const { return ref_count_ == 1; }
+ bool HasOneRef() const { return counter_holder_->ref_count == 1; }
protected:
RefCountedBase();
~RefCountedBase();
+ struct CounterHolder {
+ CounterHolder() : ref_count(0), weak_count(0) {}
+ int ref_count;
+ int weak_count; // Simulates weak pointer.
+ };
+
void AddRef() const;
// Returns true if the object should self-delete.
bool Release() const;
private:
- mutable int ref_count_;
+ mutable CounterHolder* counter_holder_;
#ifndef NDEBUG
mutable bool in_dtor_;
#endif
@@ -55,7 +61,12 @@ class RefCountedThreadSafeBase {
bool Release() const;
private:
- mutable AtomicRefCount ref_count_;
+ struct CounterHolder {
+ CounterHolder() : ref_count(0), weak_count(0) {}
+ AtomicRefCount ref_count;
+ AtomicRefCount weak_count; // Simulates weak pointer.
+ };
+ mutable CounterHolder* counter_holder_;
#ifndef NDEBUG
mutable bool in_dtor_;
#endif