c12196d47b
* removing a font family or style now always goes through the font manager. * removed FreeType "cache" remains (it wasn't used, anyway, and won't be used by us). * renamed SharedObject to ReferenceCounting as that's what it does. * the default fonts weren't deleted on shutdown. * added temporary work-around for waiting until a newly created entry is complete (just waits a moment...) - this will be fixed once Haiku supports this in a better way. git-svn-id: file:///srv/svn/repos/haiku/haiku/trunk@14833 a95241bf-73f2-0310-859d-f6bbb57e9c96
56 lines
1.1 KiB
C++
56 lines
1.1 KiB
C++
/*
|
|
* Copyright 2001-2005, Haiku.
|
|
* Distributed under the terms of the MIT License.
|
|
*
|
|
* Authors:
|
|
* DarkWyrm <bpmagic@columbus.rr.com>
|
|
* Axel Dörfler, axeld@pinc-software.de
|
|
*/
|
|
#ifndef REFERENCE_COUNTING_H
|
|
#define REFERENCE_COUNTING_H
|
|
|
|
|
|
#include <SupportDefs.h>
|
|
|
|
|
|
/*!
|
|
\class ReferenceCounting ReferenceCounting.h
|
|
\brief Base class for reference counting objects
|
|
|
|
ReferenceCounting objects track dependencies upon a particular object. In this way,
|
|
it is possible to ensure that a shared resource is not deleted if something else
|
|
needs it. How the dependency tracking is done largely depends on the child class.
|
|
*/
|
|
class ReferenceCounting {
|
|
public:
|
|
ReferenceCounting()
|
|
: fReferenceCount(1) {}
|
|
virtual ~ReferenceCounting() {}
|
|
|
|
inline void Acquire();
|
|
inline bool Release();
|
|
|
|
private:
|
|
int32 fReferenceCount;
|
|
};
|
|
|
|
|
|
inline void
|
|
ReferenceCounting::Acquire()
|
|
{
|
|
atomic_add(&fReferenceCount, 1);
|
|
}
|
|
|
|
inline bool
|
|
ReferenceCounting::Release()
|
|
{
|
|
if (atomic_add(&fReferenceCount, -1) == 1) {
|
|
delete this;
|
|
return true;
|
|
}
|
|
|
|
return false;
|
|
}
|
|
|
|
#endif /* REFERENCE_COUNTING_H */
|