btrfs: Attempt to fix GCC2 build.
[haiku.git] / src / servers / app / ReferenceCounting.h
blob2b8f5435cc8847163e79f35b96fb01617278cee6
1 /*
2 * Copyright 2001-2005, Haiku.
3 * Distributed under the terms of the MIT License.
5 * Authors:
6 * DarkWyrm <bpmagic@columbus.rr.com>
7 * Axel Dörfler, axeld@pinc-software.de
8 */
9 #ifndef REFERENCE_COUNTING_H
10 #define REFERENCE_COUNTING_H
13 #include <SupportDefs.h>
16 /*!
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 {
25 public:
26 ReferenceCounting()
27 : fReferenceCount(1) {}
28 virtual ~ReferenceCounting() {}
30 inline void Acquire();
31 inline bool Release();
33 private:
34 int32 fReferenceCount;
38 inline void
39 ReferenceCounting::Acquire()
41 atomic_add(&fReferenceCount, 1);
44 inline bool
45 ReferenceCounting::Release()
47 if (atomic_add(&fReferenceCount, -1) == 1) {
48 delete this;
49 return true;
52 return false;
55 #endif /* REFERENCE_COUNTING_H */