RefBase
ヘッダファイルRefBase.hにRefBaseクラスを実現。
class RefBase
{
public:
..........
class weakref_type
{
public:
RefBase* refBase() const;
void incWeak(const void* id);
void decWeak(const void* id);
// acquires a strong reference if there is already one.
bool attemptIncStrong(const void* id);
// acquires a weak reference if there is already one.
// This is not always safe. see ProcessState.cpp and BpBinder.cpp
// for proper use.
bool attemptIncWeak(const void* id);
//! DEBUGGING ONLY: Get current weak ref count.
int32_t getWeakCount() const;
//! DEBUGGING ONLY: Print references held on object.
void printRefs() const;
};
weakref_type* createWeak(const void* id) const;
weakref_type* getWeakRefs() const;
protected:
RefBase();
virtual ~RefBase();
private:
class weakref_impl;
private:
weakref_impl* const mRefs;
}
RefBaseクラスには、二つの内部クラスとweakref_type weakref_implがあり、見ることができます。
Weakref_typeクラスは、機能をカプセル化します。
weakref_typeを継承したクラスweakref_implも、mWeak変数を増加させました。
weakref_impl类
でRefBase.cppでweakref_implクラスを実現。
class RefBase::weakref_impl : public RefBase::weakref_type
{
public:
volatile int32_t mStrong;
volatile int32_t mWeak;
RefBase* const mBase;
volatile int32_t mFlags;