haiku/headers/private/userlandfs/shared/ObjectTracker.h
Ingo Weinhold 83812f6752 Copied userlandfs code from the test tree to the haiku source tree,
where it will be ported to Haiku.


git-svn-id: file:///srv/svn/repos/haiku/haiku/trunk@20216 a95241bf-73f2-0310-859d-f6bbb57e9c96
2007-02-24 00:30:19 +00:00

81 lines
1.6 KiB
C++

// ObjectTracker.h
#ifndef USERLAND_FS_OBJECT_TRACKER_H
#define USERLAND_FS_OBJECT_TRACKER_H
#include "DLList.h"
#include "Locker.h"
namespace UserlandFSUtil {
class ObjectTracker;
class GetObjectTrackableLink;
// ObjectTrackable
class ObjectTrackable {
public:
ObjectTrackable();
virtual ~ObjectTrackable();
private:
friend class ObjectTracker;
friend class GetObjectTrackableLink;
DLListLink<ObjectTrackable> fLink;
};
// GetObjectTrackableLink
struct GetObjectTrackableLink {
inline DLListLink<ObjectTrackable> *operator()(
ObjectTrackable* trackable) const
{
return &trackable->fLink;
}
inline const DLListLink<ObjectTrackable> *operator()(
const ObjectTrackable* trackable) const
{
return &trackable->fLink;
}
};
// ObjectTracker
class ObjectTracker {
private:
ObjectTracker();
~ObjectTracker();
public:
static ObjectTracker* InitDefault();
static void ExitDefault();
static ObjectTracker* GetDefault();
private:
friend class ObjectTrackable;
void AddTrackable(ObjectTrackable* trackable);
void RemoveTrackable(ObjectTrackable* trackable);
private:
Locker fLock;
DLList<ObjectTrackable, GetObjectTrackableLink> fTrackables;
static ObjectTracker* sTracker;
};
} // namespace UserlandFSUtil
using UserlandFSUtil::ObjectTrackable;
using UserlandFSUtil::ObjectTracker;
#ifdef DEBUG_OBJECT_TRACKING
# define ONLY_OBJECT_TRACKABLE_BASE_CLASS : private ObjectTrackable
# define FIRST_OBJECT_TRACKABLE_BASE_CLASS private ObjectTrackable,
#else
# define ONLY_OBJECT_TRACKABLE_BASE_CLASS
# define FIRST_OBJECT_TRACKABLE_BASE_CLASS
#endif
#endif // USERLAND_FS_OBJECT_TRACKER_H