Add hooks for external run-time reference adoption checks to SkRefCnt.
The reference adoption checks are to help detect memory leaks and bad usage when using SkRefCnt subclasses with Blink's RefPtr. BUG=crbug.com/304265 R=reed@google.com, bungeman@google.com Author: junov@chromium.org Review URL: https://codereview.chromium.org/25432003 git-svn-id: http://skia.googlecode.com/svn/trunk@11811 2bbb7eff-a529-9590-31e7-b0007b416f81
This commit is contained in:
parent
f32322b9ce
commit
6d2533ebd2
@ -14,6 +14,22 @@
|
|||||||
#include "SkInstCnt.h"
|
#include "SkInstCnt.h"
|
||||||
#include "SkTemplates.h"
|
#include "SkTemplates.h"
|
||||||
|
|
||||||
|
#ifdef SK_REF_CNT_BASE_INCLUDE
|
||||||
|
#include SK_REF_CNT_BASE_INCLUDE
|
||||||
|
#else
|
||||||
|
/** \class SkRefCntBase
|
||||||
|
|
||||||
|
Default implementation of SkRefCntBase. The base class' contract is to
|
||||||
|
provide an implementation of aboutToRef. Embedders of skia can specify
|
||||||
|
an alternate implementation by setting SK_REF_CNT_BASE_INCLUDE. This is
|
||||||
|
useful for adding debug run-time checks to enforce certain usage patterns.
|
||||||
|
*/
|
||||||
|
class SK_API SkRefCntBase {
|
||||||
|
public:
|
||||||
|
void aboutToRef() const {}
|
||||||
|
};
|
||||||
|
#endif
|
||||||
|
|
||||||
/** \class SkRefCnt
|
/** \class SkRefCnt
|
||||||
|
|
||||||
SkRefCnt is the base class for objects that may be shared by multiple
|
SkRefCnt is the base class for objects that may be shared by multiple
|
||||||
@ -24,7 +40,7 @@
|
|||||||
destructor to be called explicitly (or via the object going out of scope on
|
destructor to be called explicitly (or via the object going out of scope on
|
||||||
the stack or calling delete) if getRefCnt() > 1.
|
the stack or calling delete) if getRefCnt() > 1.
|
||||||
*/
|
*/
|
||||||
class SK_API SkRefCnt : SkNoncopyable {
|
class SK_API SkRefCnt : public SkRefCntBase {
|
||||||
public:
|
public:
|
||||||
SK_DECLARE_INST_COUNT_ROOT(SkRefCnt)
|
SK_DECLARE_INST_COUNT_ROOT(SkRefCnt)
|
||||||
|
|
||||||
@ -61,6 +77,7 @@ public:
|
|||||||
*/
|
*/
|
||||||
void ref() const {
|
void ref() const {
|
||||||
SkASSERT(fRefCnt > 0);
|
SkASSERT(fRefCnt > 0);
|
||||||
|
this->INHERITED::aboutToRef();
|
||||||
sk_atomic_inc(&fRefCnt); // No barrier required.
|
sk_atomic_inc(&fRefCnt); // No barrier required.
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -105,6 +122,12 @@ protected:
|
|||||||
}
|
}
|
||||||
|
|
||||||
private:
|
private:
|
||||||
|
/**
|
||||||
|
* Make SkRefCnt non-copyable.
|
||||||
|
*/
|
||||||
|
SkRefCnt(const SkRefCnt&);
|
||||||
|
SkRefCnt& operator=(const SkRefCnt&);
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Called when the ref count goes to 0.
|
* Called when the ref count goes to 0.
|
||||||
*/
|
*/
|
||||||
@ -120,7 +143,7 @@ private:
|
|||||||
|
|
||||||
mutable int32_t fRefCnt;
|
mutable int32_t fRefCnt;
|
||||||
|
|
||||||
typedef SkNoncopyable INHERITED;
|
typedef SkRefCntBase INHERITED;
|
||||||
};
|
};
|
||||||
|
|
||||||
///////////////////////////////////////////////////////////////////////////////
|
///////////////////////////////////////////////////////////////////////////////
|
||||||
|
Loading…
Reference in New Issue
Block a user