2 * Copyright 2001-2005, Haiku.
3 * Distributed under the terms of the MIT License.
6 * DarkWyrm <bpmagic@columbus.rr.com>
7 * Axel Dörfler, axeld@pinc-software.de
9 #ifndef REFERENCE_COUNTING_H
10 #define REFERENCE_COUNTING_H
13 #include <SupportDefs.h>
17 \class ReferenceCounting ReferenceCounting.h
18 \brief Base class for reference counting objects
20 ReferenceCounting objects track dependencies upon a particular object. In this way,
21 it is possible to ensure that a shared resource is not deleted if something else
22 needs it. How the dependency tracking is done largely depends on the child class.
24 class ReferenceCounting
{
27 : fReferenceCount(1) {}
28 virtual ~ReferenceCounting() {}
30 inline void Acquire();
31 inline bool Release();
34 int32 fReferenceCount
;
39 ReferenceCounting::Acquire()
41 atomic_add(&fReferenceCount
, 1);
45 ReferenceCounting::Release()
47 if (atomic_add(&fReferenceCount
, -1) == 1) {
55 #endif /* REFERENCE_COUNTING_H */