2014-12-18 20:54:34 +00:00
|
|
|
/* This Source Code Form is subject to the terms of the Mozilla Public
|
|
|
|
* License, v. 2.0. If a copy of the MPL was not distributed with this
|
|
|
|
* file, You can obtain one at http://mozilla.org/MPL/2.0/. */
|
|
|
|
|
|
|
|
#ifndef __RefCount_h__
|
|
|
|
#define __RefCount_h__
|
|
|
|
|
|
|
|
// Note: Not thread safe!
|
|
|
|
class RefCounted {
|
|
|
|
public:
|
|
|
|
void AddRef() {
|
|
|
|
++mRefCount;
|
|
|
|
}
|
|
|
|
|
2015-01-12 07:15:55 +00:00
|
|
|
uint32_t Release() {
|
|
|
|
uint32_t newCount = --mRefCount;
|
|
|
|
if (!newCount) {
|
2014-12-18 20:54:34 +00:00
|
|
|
delete this;
|
|
|
|
}
|
2015-01-12 07:15:55 +00:00
|
|
|
return newCount;
|
2014-12-18 20:54:34 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
protected:
|
|
|
|
RefCounted()
|
|
|
|
: mRefCount(0)
|
|
|
|
{
|
|
|
|
}
|
|
|
|
virtual ~RefCounted()
|
|
|
|
{
|
|
|
|
}
|
|
|
|
uint32_t mRefCount;
|
|
|
|
};
|
|
|
|
|
|
|
|
#endif // __RefCount_h__
|