btrfs: [] on the end of a struct field is a variable length array.
[haiku.git] / headers / private / userlandfs / shared / ObjectTracker.h
blob84dff5aa59ab7a10351ebe5c531fd0ab9e0fa9bd
1 /*
2 * Copyright 2001-2009, Ingo Weinhold, ingo_weinhold@gmx.de.
3 * Distributed under the terms of the MIT License.
4 */
5 #ifndef USERLAND_FS_OBJECT_TRACKER_H
6 #define USERLAND_FS_OBJECT_TRACKER_H
8 #include <util/DoublyLinkedList.h>
10 #include "Locker.h"
12 namespace UserlandFSUtil {
14 class ObjectTracker;
15 class GetObjectTrackableLink;
17 // ObjectTrackable
18 class ObjectTrackable {
19 public:
20 ObjectTrackable();
21 virtual ~ObjectTrackable();
23 private:
24 friend class ObjectTracker;
25 friend class GetObjectTrackableLink;
27 DoublyLinkedListLink<ObjectTrackable> fLink;
30 // GetObjectTrackableLink
31 struct GetObjectTrackableLink {
32 inline DoublyLinkedListLink<ObjectTrackable> *operator()(
33 ObjectTrackable* trackable) const
35 return &trackable->fLink;
38 inline const DoublyLinkedListLink<ObjectTrackable> *operator()(
39 const ObjectTrackable* trackable) const
41 return &trackable->fLink;
45 // ObjectTracker
46 class ObjectTracker {
47 private:
48 ObjectTracker();
49 ~ObjectTracker();
51 public:
53 static ObjectTracker* InitDefault();
54 static void ExitDefault();
55 static ObjectTracker* GetDefault();
57 private:
58 friend class ObjectTrackable;
60 void AddTrackable(ObjectTrackable* trackable);
61 void RemoveTrackable(ObjectTrackable* trackable);
63 private:
64 Locker fLock;
65 DoublyLinkedList<ObjectTrackable, GetObjectTrackableLink>
66 fTrackables;
68 static ObjectTracker* sTracker;
71 } // namespace UserlandFSUtil
73 using UserlandFSUtil::ObjectTrackable;
74 using UserlandFSUtil::ObjectTracker;
76 #ifdef DEBUG_OBJECT_TRACKING
77 # define ONLY_OBJECT_TRACKABLE_BASE_CLASS : private ObjectTrackable
78 # define FIRST_OBJECT_TRACKABLE_BASE_CLASS private ObjectTrackable,
79 #else
80 # define ONLY_OBJECT_TRACKABLE_BASE_CLASS
81 # define FIRST_OBJECT_TRACKABLE_BASE_CLASS
82 #endif
84 #endif // USERLAND_FS_OBJECT_TRACKER_H