template <typename T>
class RefCountedThreadSafe
Defined at line 61 of file ../../src/lib/fxl/memory/ref_counted.h
A base class for (thread-safe) reference-counted classes. Use like:
class Foo : public RefCountedThreadSafe
<Foo
> {
...
};
|~Foo()| *may* be made private (e.g., to avoid accidental deletion of objects
while there are still references to them), |Foo| should friend
|RefCountedThreadSafe
<Foo
>|; use |FRIEND_REF_COUNTED_THREAD_SAFE()| for this:
class Foo : public RefCountedThreadSafe
<Foo
> {
...
private:
FRIEND_REF_COUNTED_THREAD_SAFE(Foo);
~Foo();
...
};
Similarly, |Foo(...)| may be made private. In this case, there should either
be a static factory method performing the requisite adoption:
class Foo : public RefCountedThreadSafe
<Foo
> {
...
public:
inline static RefPtr
<Foo
> Create() { return AdoptRef(new Foo()); }
...
private:
Foo();
...
};
Or, to allow |MakeRefCounted()| to be used, use |FRIEND_MAKE_REF_COUNTED()|:
class Foo : public RefCountedThreadSafe
<Foo
> {
...
private:
FRIEND_MAKE_REF_COUNTED(Foo);
Foo();
Foo(const Bar
&
bar, bool maybe);
...
};
For now, we only have thread-safe reference counting, since that's all we
need. It's easy enough to add thread-unsafe versions if necessary.
Public Methods
void Release ()
Releases a reference to this object. This will destroy this object once the
last reference is released.
Defined at line 69 of file ../../src/lib/fxl/memory/ref_counted.h
Protected Methods
void RefCountedThreadSafe<T> ()
Constructor. Note that the object is constructed with a reference count of
1, and then must be adopted (see |AdoptRef()| in ref_ptr.h).
Defined at line 100 of file ../../src/lib/fxl/memory/ref_counted.h
void ~RefCountedThreadSafe<T> ()
Destructor. Note that this object should only be destroyed via |Release()|
(see above), or something that calls |Release()| (see, e.g., |RefPtr
<
>| in
ref_ptr.h).
Defined at line 105 of file ../../src/lib/fxl/memory/ref_counted.h