Removed several shared userlandfs classes that exist as Haiku shared or kernel
util classes as well. git-svn-id: file:///srv/svn/repos/haiku/haiku/trunk@29404 a95241bf-73f2-0310-859d-f6bbb57e9c96
This commit is contained in:
parent
5bf53b09c2
commit
c0509ccc29
@ -1,136 +0,0 @@
|
||||
//------------------------------------------------------------------------------
|
||||
// Copyright (c) 2001-2004, OpenBeOS
|
||||
//
|
||||
// Permission is hereby granted, free of charge, to any person obtaining a
|
||||
// copy of this software and associated documentation files (the "Software"),
|
||||
// to deal in the Software without restriction, including without limitation
|
||||
// the rights to use, copy, modify, merge, publish, distribute, sublicense,
|
||||
// and/or sell copies of the Software, and to permit persons to whom the
|
||||
// Software is furnished to do so, subject to the following conditions:
|
||||
//
|
||||
// The above copyright notice and this permission notice shall be included in
|
||||
// all copies or substantial portions of the Software.
|
||||
//
|
||||
// THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
||||
// IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
||||
// FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
|
||||
// AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
||||
// LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING
|
||||
// FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER
|
||||
// DEALINGS IN THE SOFTWARE.
|
||||
//
|
||||
// File Name: AutoDeleter.h
|
||||
// Author(s): Ingo Weinhold (bonefish@users.sf.net)
|
||||
// Description: Scope-based automatic deletion of objects/arrays.
|
||||
// ObjectDeleter - deletes an object
|
||||
// ArrayDeleter - deletes an array
|
||||
// MemoryDeleter - free()s malloc()ed memory
|
||||
//------------------------------------------------------------------------------
|
||||
|
||||
#ifndef _AUTO_DELETER_H
|
||||
#define _AUTO_DELETER_H
|
||||
|
||||
#include <stdlib.h>
|
||||
|
||||
namespace BPrivate {
|
||||
|
||||
// AutoDeleter
|
||||
|
||||
template<typename C, typename Delete>
|
||||
class AutoDeleter {
|
||||
public:
|
||||
inline AutoDeleter()
|
||||
: fObject(NULL)
|
||||
{
|
||||
}
|
||||
|
||||
inline AutoDeleter(C *object)
|
||||
: fObject(object)
|
||||
{
|
||||
}
|
||||
|
||||
inline ~AutoDeleter()
|
||||
{
|
||||
fDelete(fObject);
|
||||
}
|
||||
|
||||
inline void SetTo(C *object)
|
||||
{
|
||||
fDelete(fObject);
|
||||
fObject = object;
|
||||
}
|
||||
|
||||
inline C *Detach()
|
||||
{
|
||||
C *object = fObject;
|
||||
fObject = NULL;
|
||||
return object;
|
||||
}
|
||||
|
||||
private:
|
||||
C *fObject;
|
||||
Delete fDelete;
|
||||
};
|
||||
|
||||
|
||||
// ObjectDeleter
|
||||
|
||||
template<typename C>
|
||||
struct ObjectDelete
|
||||
{
|
||||
inline void operator()(C *object)
|
||||
{
|
||||
delete object;
|
||||
}
|
||||
};
|
||||
|
||||
template<typename C>
|
||||
struct ObjectDeleter : AutoDeleter<C, ObjectDelete<C> >
|
||||
{
|
||||
ObjectDeleter() : AutoDeleter<C, ObjectDelete<C> >() {}
|
||||
ObjectDeleter(C *object) : AutoDeleter<C, ObjectDelete<C> >(object) {}
|
||||
};
|
||||
|
||||
|
||||
// ArrayDeleter
|
||||
|
||||
template<typename C>
|
||||
struct ArrayDelete
|
||||
{
|
||||
inline void operator()(C *array)
|
||||
{
|
||||
delete[] array;
|
||||
}
|
||||
};
|
||||
|
||||
template<typename C>
|
||||
struct ArrayDeleter : AutoDeleter<C, ArrayDelete<C> >
|
||||
{
|
||||
ArrayDeleter() : AutoDeleter<C, ArrayDelete<C> >() {}
|
||||
ArrayDeleter(C *array) : AutoDeleter<C, ArrayDelete<C> >(array) {}
|
||||
};
|
||||
|
||||
|
||||
// MemoryDeleter
|
||||
|
||||
struct MemoryDelete
|
||||
{
|
||||
inline void operator()(void *memory)
|
||||
{
|
||||
free(memory);
|
||||
}
|
||||
};
|
||||
|
||||
struct MemoryDeleter : AutoDeleter<void, MemoryDelete >
|
||||
{
|
||||
MemoryDeleter() : AutoDeleter<void, MemoryDelete >() {}
|
||||
MemoryDeleter(void *memory) : AutoDeleter<void, MemoryDelete >(memory) {}
|
||||
};
|
||||
|
||||
} // namespace BPrivate
|
||||
|
||||
using BPrivate::ObjectDeleter;
|
||||
using BPrivate::ArrayDeleter;
|
||||
using BPrivate::MemoryDeleter;
|
||||
|
||||
#endif // _AUTO_DELETER_H
|
@ -1,181 +0,0 @@
|
||||
// AutoLocker.h
|
||||
//
|
||||
// Copyright (c) 2004, Ingo Weinhold (bonefish@cs.tu-berlin.de)
|
||||
//
|
||||
// Permission is hereby granted, free of charge, to any person obtaining a
|
||||
// copy of this software and associated documentation files (the "Software"),
|
||||
// to deal in the Software without restriction, including without limitation
|
||||
// the rights to use, copy, modify, merge, publish, distribute, sublicense,
|
||||
// and/or sell copies of the Software, and to permit persons to whom the
|
||||
// Software is furnished to do so, subject to the following conditions:
|
||||
//
|
||||
// The above copyright notice and this permission notice shall be included in
|
||||
// all copies or substantial portions of the Software.
|
||||
//
|
||||
// THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
||||
// IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
||||
// FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL
|
||||
// THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
||||
// LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING
|
||||
// FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER
|
||||
// DEALINGS IN THE SOFTWARE.
|
||||
//
|
||||
// Except as contained in this notice, the name of a copyright holder shall
|
||||
// not be used in advertising or otherwise to promote the sale, use or other
|
||||
// dealings in this Software without prior written authorization of the
|
||||
// copyright holder.
|
||||
|
||||
#ifndef AUTO_LOCKER_H
|
||||
#define AUTO_LOCKER_H
|
||||
|
||||
#include <SupportDefs.h>
|
||||
|
||||
// locking
|
||||
|
||||
// AutoLockerStandardLocking
|
||||
template<typename Lockable>
|
||||
class AutoLockerStandardLocking {
|
||||
public:
|
||||
inline bool Lock(Lockable *lockable)
|
||||
{
|
||||
return lockable->Lock();
|
||||
}
|
||||
|
||||
inline void Unlock(Lockable *lockable)
|
||||
{
|
||||
lockable->Unlock();
|
||||
}
|
||||
};
|
||||
|
||||
// AutoLockerReadLocking
|
||||
template<typename Lockable>
|
||||
class AutoLockerReadLocking {
|
||||
public:
|
||||
inline bool Lock(Lockable *lockable)
|
||||
{
|
||||
return lockable->ReadLock();
|
||||
}
|
||||
|
||||
inline void Unlock(Lockable *lockable)
|
||||
{
|
||||
lockable->ReadUnlock();
|
||||
}
|
||||
};
|
||||
|
||||
// AutoLockerWriteLocking
|
||||
template<typename Lockable>
|
||||
class AutoLockerWriteLocking {
|
||||
public:
|
||||
inline bool Lock(Lockable *lockable)
|
||||
{
|
||||
return lockable->WriteLock();
|
||||
}
|
||||
|
||||
inline void Unlock(Lockable *lockable)
|
||||
{
|
||||
lockable->WriteUnlock();
|
||||
}
|
||||
};
|
||||
|
||||
|
||||
template<typename Lockable,
|
||||
typename Locking = AutoLockerStandardLocking<Lockable> >
|
||||
class AutoLocker {
|
||||
private:
|
||||
typedef AutoLocker<Lockable, Locking> ThisClass;
|
||||
public:
|
||||
inline AutoLocker()
|
||||
: fLockable(NULL),
|
||||
fLocked(false)
|
||||
{
|
||||
}
|
||||
|
||||
inline AutoLocker(Lockable *lockable, bool alreadyLocked = false,
|
||||
bool lockIfNotLocked = true)
|
||||
: fLockable(lockable),
|
||||
fLocked(fLockable && alreadyLocked)
|
||||
{
|
||||
if (!alreadyLocked && lockIfNotLocked)
|
||||
Lock();
|
||||
}
|
||||
|
||||
inline AutoLocker(Lockable &lockable, bool alreadyLocked = false,
|
||||
bool lockIfNotLocked = true)
|
||||
: fLockable(&lockable),
|
||||
fLocked(fLockable && alreadyLocked)
|
||||
{
|
||||
if (!alreadyLocked && lockIfNotLocked)
|
||||
Lock();
|
||||
}
|
||||
|
||||
inline ~AutoLocker()
|
||||
{
|
||||
Unlock();
|
||||
}
|
||||
|
||||
inline void SetTo(Lockable *lockable, bool alreadyLocked,
|
||||
bool lockIfNotLocked = true)
|
||||
{
|
||||
Unlock();
|
||||
fLockable = lockable;
|
||||
fLocked = alreadyLocked;
|
||||
if (!alreadyLocked && lockIfNotLocked)
|
||||
Lock();
|
||||
}
|
||||
|
||||
inline void SetTo(Lockable &lockable, bool alreadyLocked,
|
||||
bool lockIfNotLocked = true)
|
||||
{
|
||||
SetTo(&lockable, alreadyLocked, lockIfNotLocked);
|
||||
}
|
||||
|
||||
inline void Unset()
|
||||
{
|
||||
Unlock();
|
||||
Detach();
|
||||
}
|
||||
|
||||
inline bool Lock()
|
||||
{
|
||||
if (fLockable && !fLocked)
|
||||
fLocked = fLocking.Lock(fLockable);
|
||||
return fLocked;
|
||||
}
|
||||
|
||||
inline void Unlock()
|
||||
{
|
||||
if (fLockable && fLocked) {
|
||||
fLocking.Unlock(fLockable);
|
||||
fLocked = false;
|
||||
}
|
||||
}
|
||||
|
||||
inline void Detach()
|
||||
{
|
||||
fLockable = NULL;
|
||||
fLocked = false;
|
||||
}
|
||||
|
||||
inline AutoLocker<Lockable, Locking> &operator=(Lockable *lockable)
|
||||
{
|
||||
SetTo(lockable);
|
||||
return *this;
|
||||
}
|
||||
|
||||
inline AutoLocker<Lockable, Locking> &operator=(Lockable &lockable)
|
||||
{
|
||||
SetTo(&lockable);
|
||||
return *this;
|
||||
}
|
||||
|
||||
inline bool IsLocked() const { return fLocked; }
|
||||
|
||||
inline operator bool() const { return fLocked; }
|
||||
|
||||
private:
|
||||
Lockable *fLockable;
|
||||
bool fLocked;
|
||||
Locking fLocking;
|
||||
};
|
||||
|
||||
#endif // AUTO_LOCKER_H
|
@ -1,384 +0,0 @@
|
||||
// DLList.h
|
||||
//
|
||||
// Copyright (c) 2003, Ingo Weinhold (bonefish@cs.tu-berlin.de)
|
||||
//
|
||||
// Permission is hereby granted, free of charge, to any person obtaining a
|
||||
// copy of this software and associated documentation files (the "Software"),
|
||||
// to deal in the Software without restriction, including without limitation
|
||||
// the rights to use, copy, modify, merge, publish, distribute, sublicense,
|
||||
// and/or sell copies of the Software, and to permit persons to whom the
|
||||
// Software is furnished to do so, subject to the following conditions:
|
||||
//
|
||||
// The above copyright notice and this permission notice shall be included in
|
||||
// all copies or substantial portions of the Software.
|
||||
//
|
||||
// THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
||||
// IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
||||
// FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL
|
||||
// THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
||||
// LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING
|
||||
// FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER
|
||||
// DEALINGS IN THE SOFTWARE.
|
||||
//
|
||||
// Except as contained in this notice, the name of a copyright holder shall
|
||||
// not be used in advertising or otherwise to promote the sale, use or other
|
||||
// dealings in this Software without prior written authorization of the
|
||||
// copyright holder.
|
||||
|
||||
#ifndef DL_LIST_H
|
||||
#define DL_LIST_H
|
||||
|
||||
#include <SupportDefs.h>
|
||||
|
||||
namespace UserlandFSUtil {
|
||||
|
||||
// DLListLink
|
||||
template<typename Element>
|
||||
class DLListLink {
|
||||
public:
|
||||
DLListLink() : previous(NULL), next(NULL) {}
|
||||
~DLListLink() {}
|
||||
|
||||
Element *previous;
|
||||
Element *next;
|
||||
};
|
||||
|
||||
// DLListLinkImpl
|
||||
template<typename Element>
|
||||
class DLListLinkImpl {
|
||||
private:
|
||||
typedef DLListLink<Element> MyLink;
|
||||
|
||||
public:
|
||||
DLListLinkImpl() : fDLListLink() {}
|
||||
~DLListLinkImpl() {}
|
||||
|
||||
MyLink *GetDLListLink() { return &fDLListLink; }
|
||||
const MyLink *GetDLListLink() const { return &fDLListLink; }
|
||||
|
||||
private:
|
||||
MyLink fDLListLink;
|
||||
};
|
||||
|
||||
// DLListStandardGetLink
|
||||
template<typename Element>
|
||||
class DLListStandardGetLink {
|
||||
private:
|
||||
typedef DLListLink<Element> Link;
|
||||
|
||||
public:
|
||||
inline Link *operator()(Element *element) const
|
||||
{
|
||||
return element->GetDLListLink();
|
||||
}
|
||||
|
||||
inline const Link *operator()(const Element *element) const
|
||||
{
|
||||
return element->GetDLListLink();
|
||||
}
|
||||
};
|
||||
|
||||
// for convenience
|
||||
#define DL_LIST_TEMPLATE_LIST template<typename Element, typename GetLink>
|
||||
#define DL_LIST_CLASS_NAME DLList<Element, GetLink>
|
||||
|
||||
// DLList
|
||||
template<typename Element, typename GetLink = DLListStandardGetLink<Element> >
|
||||
class DLList {
|
||||
private:
|
||||
typedef DLList<Element, GetLink> List;
|
||||
typedef DLListLink<Element> Link;
|
||||
|
||||
public:
|
||||
class Iterator {
|
||||
public:
|
||||
Iterator(List *list)
|
||||
: fList(list),
|
||||
fCurrent(NULL),
|
||||
fNext(fList->GetFirst())
|
||||
{
|
||||
}
|
||||
|
||||
Iterator(const Iterator &other)
|
||||
{
|
||||
*this = other;
|
||||
}
|
||||
|
||||
bool HasNext() const
|
||||
{
|
||||
return fNext;
|
||||
}
|
||||
|
||||
Element *Next()
|
||||
{
|
||||
fCurrent = fNext;
|
||||
if (fNext)
|
||||
fNext = fList->GetNext(fNext);
|
||||
return fCurrent;
|
||||
}
|
||||
|
||||
Element *Remove()
|
||||
{
|
||||
Element *element = fCurrent;
|
||||
if (fCurrent) {
|
||||
fList->Remove(fCurrent);
|
||||
fCurrent = NULL;
|
||||
}
|
||||
return element;
|
||||
}
|
||||
|
||||
Iterator &operator=(const Iterator &other)
|
||||
{
|
||||
fList = other.fList;
|
||||
fCurrent = other.fCurrent;
|
||||
fNext = other.fNext;
|
||||
return *this;
|
||||
}
|
||||
|
||||
private:
|
||||
List *fList;
|
||||
Element *fCurrent;
|
||||
Element *fNext;
|
||||
};
|
||||
|
||||
class ConstIterator {
|
||||
public:
|
||||
ConstIterator(const List *list)
|
||||
: fList(list),
|
||||
fNext(list->GetFirst())
|
||||
{
|
||||
}
|
||||
|
||||
ConstIterator(const ConstIterator &other)
|
||||
{
|
||||
*this = other;
|
||||
}
|
||||
|
||||
bool HasNext() const
|
||||
{
|
||||
return fNext;
|
||||
}
|
||||
|
||||
Element *Next()
|
||||
{
|
||||
Element *element = fNext;
|
||||
if (fNext)
|
||||
fNext = fList->GetNext(fNext);
|
||||
return element;
|
||||
}
|
||||
|
||||
ConstIterator &operator=(const ConstIterator &other)
|
||||
{
|
||||
fList = other.fList;
|
||||
fNext = other.fNext;
|
||||
return *this;
|
||||
}
|
||||
|
||||
private:
|
||||
const List *fList;
|
||||
Element *fNext;
|
||||
};
|
||||
|
||||
public:
|
||||
DLList() : fFirst(NULL), fLast(NULL) {}
|
||||
DLList(const GetLink &getLink)
|
||||
: fFirst(NULL), fLast(NULL), fGetLink(getLink) {}
|
||||
~DLList() {}
|
||||
|
||||
inline bool IsEmpty() const { return (fFirst == NULL); }
|
||||
|
||||
inline void Insert(Element *element, bool back = true);
|
||||
inline void Remove(Element *element);
|
||||
|
||||
inline void Swap(Element *a, Element *b);
|
||||
|
||||
inline void MoveFrom(DL_LIST_CLASS_NAME *fromList);
|
||||
|
||||
inline void RemoveAll();
|
||||
|
||||
inline Element *GetFirst() const { return fFirst; }
|
||||
inline Element *GetLast() const { return fLast; }
|
||||
|
||||
inline Element *GetHead() const { return fFirst; }
|
||||
inline Element *GetTail() const { return fLast; }
|
||||
|
||||
inline Element *GetPrevious(Element *element) const;
|
||||
inline Element *GetNext(Element *element) const;
|
||||
|
||||
inline int32 Size() const;
|
||||
// O(n)!
|
||||
|
||||
inline Iterator GetIterator() { return Iterator(this); }
|
||||
inline ConstIterator GetIterator() const { return ConstIterator(this); }
|
||||
|
||||
private:
|
||||
Element *fFirst;
|
||||
Element *fLast;
|
||||
GetLink fGetLink;
|
||||
};
|
||||
|
||||
} // namespace UserlandFSUtil
|
||||
|
||||
using UserlandFSUtil::DLList;
|
||||
using UserlandFSUtil::DLListLink;
|
||||
using UserlandFSUtil::DLListLinkImpl;
|
||||
|
||||
|
||||
// inline methods
|
||||
|
||||
// Insert
|
||||
DL_LIST_TEMPLATE_LIST
|
||||
void
|
||||
DL_LIST_CLASS_NAME::Insert(Element *element, bool back)
|
||||
{
|
||||
if (element) {
|
||||
if (back) {
|
||||
// append
|
||||
Link *elLink = fGetLink(element);
|
||||
elLink->previous = fLast;
|
||||
elLink->next = NULL;
|
||||
if (fLast)
|
||||
fGetLink(fLast)->next = element;
|
||||
else
|
||||
fFirst = element;
|
||||
fLast = element;
|
||||
} else {
|
||||
// prepend
|
||||
Link *elLink = fGetLink(element);
|
||||
elLink->previous = NULL;
|
||||
elLink->next = fFirst;
|
||||
if (fFirst)
|
||||
fGetLink(fFirst)->previous = element;
|
||||
else
|
||||
fLast = element;
|
||||
fFirst = element;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
// Remove
|
||||
DL_LIST_TEMPLATE_LIST
|
||||
void
|
||||
DL_LIST_CLASS_NAME::Remove(Element *element)
|
||||
{
|
||||
if (element) {
|
||||
Link *elLink = fGetLink(element);
|
||||
if (elLink->previous)
|
||||
fGetLink(elLink->previous)->next = elLink->next;
|
||||
else
|
||||
fFirst = elLink->next;
|
||||
if (elLink->next)
|
||||
fGetLink(elLink->next)->previous = elLink->previous;
|
||||
else
|
||||
fLast = elLink->previous;
|
||||
elLink->previous = NULL;
|
||||
elLink->next = NULL;
|
||||
}
|
||||
}
|
||||
|
||||
// Swap
|
||||
DL_LIST_TEMPLATE_LIST
|
||||
void
|
||||
DL_LIST_CLASS_NAME::Swap(Element *a, Element *b)
|
||||
{
|
||||
if (a && b && a != b) {
|
||||
Link *aLink = fGetLink(a);
|
||||
Link *bLink = fGetLink(b);
|
||||
Element *aPrev = aLink->previous;
|
||||
Element *bPrev = bLink->previous;
|
||||
Element *aNext = aLink->next;
|
||||
Element *bNext = bLink->next;
|
||||
// place a
|
||||
if (bPrev)
|
||||
fGetLink(bPrev)->next = a;
|
||||
else
|
||||
fFirst = a;
|
||||
if (bNext)
|
||||
fGetLink(bNext)->previous = a;
|
||||
else
|
||||
fLast = a;
|
||||
aLink->previous = bPrev;
|
||||
aLink->next = bNext;
|
||||
// place b
|
||||
if (aPrev)
|
||||
fGetLink(aPrev)->next = b;
|
||||
else
|
||||
fFirst = b;
|
||||
if (aNext)
|
||||
fGetLink(aNext)->previous = b;
|
||||
else
|
||||
fLast = b;
|
||||
bLink->previous = aPrev;
|
||||
bLink->next = aNext;
|
||||
}
|
||||
}
|
||||
|
||||
// MoveFrom
|
||||
DL_LIST_TEMPLATE_LIST
|
||||
void
|
||||
DL_LIST_CLASS_NAME::MoveFrom(DL_LIST_CLASS_NAME *fromList)
|
||||
{
|
||||
if (fromList && fromList->fFirst) {
|
||||
if (fFirst) {
|
||||
fGetLink(fLast)->next = fromList->fFirst;
|
||||
fGetLink(fFirst)->previous = fLast;
|
||||
fLast = fromList->fLast;
|
||||
} else {
|
||||
fFirst = fromList->fFirst;
|
||||
fLast = fromList->fLast;
|
||||
}
|
||||
fromList->fFirst = NULL;
|
||||
fromList->fLast = NULL;
|
||||
}
|
||||
}
|
||||
|
||||
// RemoveAll
|
||||
DL_LIST_TEMPLATE_LIST
|
||||
void
|
||||
DL_LIST_CLASS_NAME::RemoveAll()
|
||||
{
|
||||
Element *element = fFirst;
|
||||
while (element) {
|
||||
Link *elLink = fGetLink(element);
|
||||
element = elLink->next;
|
||||
elLink->previous = NULL;
|
||||
elLink->next = NULL;
|
||||
}
|
||||
fFirst = NULL;
|
||||
fLast = NULL;
|
||||
}
|
||||
|
||||
// GetPrevious
|
||||
DL_LIST_TEMPLATE_LIST
|
||||
Element *
|
||||
DL_LIST_CLASS_NAME::GetPrevious(Element *element) const
|
||||
{
|
||||
Element *result = NULL;
|
||||
if (element)
|
||||
result = fGetLink(element)->previous;
|
||||
return result;
|
||||
}
|
||||
|
||||
// GetNext
|
||||
DL_LIST_TEMPLATE_LIST
|
||||
Element *
|
||||
DL_LIST_CLASS_NAME::GetNext(Element *element) const
|
||||
{
|
||||
Element *result = NULL;
|
||||
if (element)
|
||||
result = fGetLink(element)->next;
|
||||
return result;
|
||||
}
|
||||
|
||||
// Size
|
||||
DL_LIST_TEMPLATE_LIST
|
||||
int32
|
||||
DL_LIST_CLASS_NAME::Size() const
|
||||
{
|
||||
int32 count = 0;
|
||||
for (Element* element = GetFirst(); element; element = GetNext(element))
|
||||
count++;
|
||||
return count;
|
||||
}
|
||||
|
||||
#endif // DL_LIST_H
|
@ -1,9 +1,12 @@
|
||||
// ObjectTracker.h
|
||||
|
||||
/*
|
||||
* Copyright 2001-2009, Ingo Weinhold, ingo_weinhold@gmx.de.
|
||||
* Distributed under the terms of the MIT License.
|
||||
*/
|
||||
#ifndef USERLAND_FS_OBJECT_TRACKER_H
|
||||
#define USERLAND_FS_OBJECT_TRACKER_H
|
||||
|
||||
#include "DLList.h"
|
||||
#include <util/DoublyLinkedList.h>
|
||||
|
||||
#include "Locker.h"
|
||||
|
||||
namespace UserlandFSUtil {
|
||||
@ -21,18 +24,18 @@ private:
|
||||
friend class ObjectTracker;
|
||||
friend class GetObjectTrackableLink;
|
||||
|
||||
DLListLink<ObjectTrackable> fLink;
|
||||
DoublyLinkedListLink<ObjectTrackable> fLink;
|
||||
};
|
||||
|
||||
// GetObjectTrackableLink
|
||||
struct GetObjectTrackableLink {
|
||||
inline DLListLink<ObjectTrackable> *operator()(
|
||||
inline DoublyLinkedListLink<ObjectTrackable> *operator()(
|
||||
ObjectTrackable* trackable) const
|
||||
{
|
||||
return &trackable->fLink;
|
||||
}
|
||||
|
||||
inline const DLListLink<ObjectTrackable> *operator()(
|
||||
inline const DoublyLinkedListLink<ObjectTrackable> *operator()(
|
||||
const ObjectTrackable* trackable) const
|
||||
{
|
||||
return &trackable->fLink;
|
||||
@ -59,7 +62,8 @@ private:
|
||||
|
||||
private:
|
||||
Locker fLock;
|
||||
DLList<ObjectTrackable, GetObjectTrackableLink> fTrackables;
|
||||
DoublyLinkedList<ObjectTrackable, GetObjectTrackableLink>
|
||||
fTrackables;
|
||||
|
||||
static ObjectTracker* sTracker;
|
||||
};
|
||||
|
@ -1,118 +0,0 @@
|
||||
// Referencable.h
|
||||
|
||||
#ifndef USERLAND_FS_REFERENCABLE_H
|
||||
#define USERLAND_FS_REFERENCABLE_H
|
||||
|
||||
#include <SupportDefs.h>
|
||||
|
||||
#include "ObjectTracker.h"
|
||||
|
||||
namespace UserlandFSUtil {
|
||||
|
||||
// Referencable
|
||||
class Referencable ONLY_OBJECT_TRACKABLE_BASE_CLASS {
|
||||
public:
|
||||
Referencable(
|
||||
bool deleteWhenUnreferenced = false);
|
||||
virtual ~Referencable();
|
||||
|
||||
void AddReference();
|
||||
bool RemoveReference(); // returns true after last
|
||||
|
||||
int32 CountReferences() const;
|
||||
|
||||
protected:
|
||||
vint32 fReferenceCount;
|
||||
bool fDeleteWhenUnreferenced;
|
||||
};
|
||||
|
||||
// Reference
|
||||
template<typename Type>
|
||||
class Reference {
|
||||
public:
|
||||
Reference()
|
||||
: fObject(NULL)
|
||||
{
|
||||
}
|
||||
|
||||
Reference(Type* object, bool alreadyHasReference = false)
|
||||
: fObject(NULL)
|
||||
{
|
||||
SetTo(object, alreadyHasReference);
|
||||
}
|
||||
|
||||
Reference(const Reference<Type>& other)
|
||||
: fObject(NULL)
|
||||
{
|
||||
SetTo(other.fObject);
|
||||
}
|
||||
|
||||
~Reference()
|
||||
{
|
||||
Unset();
|
||||
}
|
||||
|
||||
void SetTo(Type* object, bool alreadyHasReference = false)
|
||||
{
|
||||
Unset();
|
||||
fObject = object;
|
||||
if (fObject && !alreadyHasReference)
|
||||
fObject->AddReference();
|
||||
}
|
||||
|
||||
void Unset()
|
||||
{
|
||||
if (fObject) {
|
||||
fObject->RemoveReference();
|
||||
fObject = NULL;
|
||||
}
|
||||
}
|
||||
|
||||
Type* Get() const
|
||||
{
|
||||
return fObject;
|
||||
}
|
||||
|
||||
Type* Detach()
|
||||
{
|
||||
Type* object = fObject;
|
||||
fObject = NULL;
|
||||
return object;
|
||||
}
|
||||
|
||||
Type& operator*() const
|
||||
{
|
||||
return *fObject;
|
||||
}
|
||||
|
||||
Type* operator->() const
|
||||
{
|
||||
return fObject;
|
||||
}
|
||||
|
||||
Reference& operator=(const Reference<Type>& other)
|
||||
{
|
||||
SetTo(other.fObject);
|
||||
return *this;
|
||||
}
|
||||
|
||||
bool operator==(const Reference<Type>& other) const
|
||||
{
|
||||
return (fObject == other.fObject);
|
||||
}
|
||||
|
||||
bool operator!=(const Reference<Type>& other) const
|
||||
{
|
||||
return (fObject != other.fObject);
|
||||
}
|
||||
|
||||
private:
|
||||
Type* fObject;
|
||||
};
|
||||
|
||||
} // namespace UserlandFSUtil
|
||||
|
||||
using UserlandFSUtil::Referencable;
|
||||
using UserlandFSUtil::Reference;
|
||||
|
||||
#endif // USERLAND_FS_REFERENCABLE_H
|
@ -1,332 +0,0 @@
|
||||
// SLList.h
|
||||
|
||||
#ifndef SL_LIST_H
|
||||
#define SL_LIST_H
|
||||
|
||||
#include <SupportDefs.h>
|
||||
|
||||
namespace UserlandFSUtil {
|
||||
|
||||
// SLListLink
|
||||
template<typename Element>
|
||||
class SLListLink {
|
||||
public:
|
||||
SLListLink() : next(NULL) {}
|
||||
~SLListLink() {}
|
||||
|
||||
Element *next;
|
||||
};
|
||||
|
||||
// SLListLinkImpl
|
||||
template<typename Element>
|
||||
class SLListLinkImpl {
|
||||
private:
|
||||
typedef SLListLink<Element> Link;
|
||||
|
||||
public:
|
||||
SLListLinkImpl() : fSLListLink() {}
|
||||
~SLListLinkImpl() {}
|
||||
|
||||
Link *GetSLListLink() { return &fSLListLink; }
|
||||
const Link *GetSLListLink() const { return &fSLListLink; }
|
||||
|
||||
private:
|
||||
Link fSLListLink;
|
||||
};
|
||||
|
||||
// SLListStandardGetLink
|
||||
template<typename Element>
|
||||
class SLListStandardGetLink {
|
||||
private:
|
||||
typedef SLListLink<Element> Link;
|
||||
|
||||
public:
|
||||
inline Link *operator()(Element *element) const
|
||||
{
|
||||
return element->GetSLListLink();
|
||||
}
|
||||
|
||||
inline const Link *operator()(const Element *element) const
|
||||
{
|
||||
return element->GetSLListLink();
|
||||
}
|
||||
};
|
||||
|
||||
// for convenience
|
||||
#define SL_LIST_TEMPLATE_LIST template<typename Element, typename GetLink>
|
||||
#define SL_LIST_CLASS_NAME SLList<Element, GetLink>
|
||||
|
||||
// SLList
|
||||
template<typename Element, typename GetLink = SLListStandardGetLink<Element> >
|
||||
class SLList {
|
||||
private:
|
||||
typedef SLList<Element, GetLink> List;
|
||||
typedef SLListLink<Element> Link;
|
||||
|
||||
public:
|
||||
class Iterator {
|
||||
public:
|
||||
Iterator(List *list)
|
||||
: fList(list),
|
||||
fPrevious(NULL),
|
||||
fCurrent(NULL),
|
||||
fNext(fList->GetFirst())
|
||||
{
|
||||
}
|
||||
|
||||
Iterator(const Iterator &other)
|
||||
{
|
||||
*this = other;
|
||||
}
|
||||
|
||||
bool HasNext() const
|
||||
{
|
||||
return fNext;
|
||||
}
|
||||
|
||||
Element *Next()
|
||||
{
|
||||
if (fCurrent)
|
||||
fPrevious = fCurrent;
|
||||
|
||||
fCurrent = fNext;
|
||||
|
||||
if (fNext)
|
||||
fNext = fList->GetNext(fNext);
|
||||
|
||||
return fCurrent;
|
||||
}
|
||||
|
||||
Element *Remove()
|
||||
{
|
||||
Element *element = fCurrent;
|
||||
if (fCurrent) {
|
||||
fList->_Remove(fPrevious, fCurrent);
|
||||
fCurrent = NULL;
|
||||
}
|
||||
return element;
|
||||
}
|
||||
|
||||
Iterator &operator=(const Iterator &other)
|
||||
{
|
||||
fList = other.fList;
|
||||
fPrevious = other.fPrevious;
|
||||
fCurrent = other.fCurrent;
|
||||
fNext = other.fNext;
|
||||
return *this;
|
||||
}
|
||||
|
||||
private:
|
||||
List *fList;
|
||||
Element *fPrevious;
|
||||
Element *fCurrent;
|
||||
Element *fNext;
|
||||
};
|
||||
|
||||
class ConstIterator {
|
||||
public:
|
||||
ConstIterator(const List *list)
|
||||
: fList(list),
|
||||
fNext(list->GetFirst())
|
||||
{
|
||||
}
|
||||
|
||||
ConstIterator(const ConstIterator &other)
|
||||
{
|
||||
*this = other;
|
||||
}
|
||||
|
||||
bool HasNext() const
|
||||
{
|
||||
return fNext;
|
||||
}
|
||||
|
||||
Element *Next()
|
||||
{
|
||||
Element *element = fNext;
|
||||
if (fNext)
|
||||
fNext = fList->GetNext(fNext);
|
||||
return element;
|
||||
}
|
||||
|
||||
ConstIterator &operator=(const ConstIterator &other)
|
||||
{
|
||||
fList = other.fList;
|
||||
fNext = other.fNext;
|
||||
return *this;
|
||||
}
|
||||
|
||||
private:
|
||||
const List *fList;
|
||||
Element *fNext;
|
||||
};
|
||||
|
||||
public:
|
||||
SLList() : fFirst(NULL), fLast(NULL) {}
|
||||
SLList(const GetLink &getLink)
|
||||
: fFirst(NULL), fLast(NULL), fGetLink(getLink) {}
|
||||
~SLList() {}
|
||||
|
||||
inline bool IsEmpty() const { return (fFirst == NULL); }
|
||||
|
||||
inline void Insert(Element *element, bool back = true);
|
||||
inline void InsertAfter(Element *previous, Element *element);
|
||||
inline void Remove(Element *element);
|
||||
// O(n)!
|
||||
|
||||
inline void MoveFrom(SL_LIST_CLASS_NAME *fromList);
|
||||
|
||||
inline void RemoveAll();
|
||||
|
||||
inline Element *GetFirst() const { return fFirst; }
|
||||
inline Element *GetLast() const { return fLast; }
|
||||
|
||||
inline Element *GetHead() const { return fFirst; }
|
||||
inline Element *GetTail() const { return fLast; }
|
||||
|
||||
inline Element *GetNext(Element *element) const;
|
||||
|
||||
inline int32 Size() const;
|
||||
// O(n)!
|
||||
|
||||
inline Iterator GetIterator() { return Iterator(this); }
|
||||
inline ConstIterator GetIterator() const { return ConstIterator(this); }
|
||||
|
||||
private:
|
||||
friend class Iterator;
|
||||
|
||||
inline void _Remove(Element *previous, Element *element);
|
||||
|
||||
private:
|
||||
Element *fFirst;
|
||||
Element *fLast;
|
||||
GetLink fGetLink;
|
||||
};
|
||||
|
||||
} // namespace UserlandFSUtil
|
||||
|
||||
using UserlandFSUtil::SLList;
|
||||
using UserlandFSUtil::SLListLink;
|
||||
using UserlandFSUtil::SLListLinkImpl;
|
||||
|
||||
|
||||
// inline methods
|
||||
|
||||
// Insert
|
||||
SL_LIST_TEMPLATE_LIST
|
||||
void
|
||||
SL_LIST_CLASS_NAME::Insert(Element *element, bool back)
|
||||
{
|
||||
InsertAfter((back ? fLast : NULL), element);
|
||||
}
|
||||
|
||||
// InsertAfter
|
||||
SL_LIST_TEMPLATE_LIST
|
||||
void
|
||||
SL_LIST_CLASS_NAME::InsertAfter(Element *previous, Element *element)
|
||||
{
|
||||
if (element) {
|
||||
Link *elLink = fGetLink(element);
|
||||
if (previous) {
|
||||
// insert after previous element
|
||||
Link *prevLink = fGetLink(previous);
|
||||
elLink->next = prevLink->next;
|
||||
prevLink->next = element;
|
||||
} else {
|
||||
// no previous element given: prepend
|
||||
elLink->next = fFirst;
|
||||
fFirst = element;
|
||||
}
|
||||
|
||||
// element may be new last element
|
||||
if (fLast == previous)
|
||||
fLast = element;
|
||||
}
|
||||
}
|
||||
|
||||
// Remove
|
||||
SL_LIST_TEMPLATE_LIST
|
||||
void
|
||||
SL_LIST_CLASS_NAME::Remove(Element *element)
|
||||
{
|
||||
if (!element)
|
||||
return;
|
||||
|
||||
for (Iterator it = GetIterator(); it.HasNext();) {
|
||||
if (element == it.Next()) {
|
||||
it.Remove();
|
||||
return;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
// MoveFrom
|
||||
SL_LIST_TEMPLATE_LIST
|
||||
void
|
||||
SL_LIST_CLASS_NAME::MoveFrom(SL_LIST_CLASS_NAME *fromList)
|
||||
{
|
||||
if (fromList && fromList->fFirst) {
|
||||
if (fFirst) {
|
||||
fGetLink(fLast)->next = fromList->fFirst;
|
||||
fLast = fromList->fLast;
|
||||
} else {
|
||||
fFirst = fromList->fFirst;
|
||||
fLast = fromList->fLast;
|
||||
}
|
||||
fromList->fFirst = NULL;
|
||||
fromList->fLast = NULL;
|
||||
}
|
||||
}
|
||||
|
||||
// RemoveAll
|
||||
SL_LIST_TEMPLATE_LIST
|
||||
void
|
||||
SL_LIST_CLASS_NAME::RemoveAll()
|
||||
{
|
||||
Element *element = fFirst;
|
||||
while (element) {
|
||||
Link *elLink = fGetLink(element);
|
||||
element = elLink->next;
|
||||
elLink->next = NULL;
|
||||
}
|
||||
fFirst = NULL;
|
||||
fLast = NULL;
|
||||
}
|
||||
|
||||
// GetNext
|
||||
SL_LIST_TEMPLATE_LIST
|
||||
Element *
|
||||
SL_LIST_CLASS_NAME::GetNext(Element *element) const
|
||||
{
|
||||
return (element ? fGetLink(element)->next : NULL);
|
||||
}
|
||||
|
||||
// _Remove
|
||||
SL_LIST_TEMPLATE_LIST
|
||||
void
|
||||
SL_LIST_CLASS_NAME::_Remove(Element *previous, Element *element)
|
||||
{
|
||||
Link *elLink = fGetLink(element);
|
||||
if (previous)
|
||||
fGetLink(previous)->next = elLink->next;
|
||||
else
|
||||
fFirst = elLink->next;
|
||||
|
||||
if (element == fLast)
|
||||
fLast = previous;
|
||||
|
||||
elLink->next = NULL;
|
||||
}
|
||||
|
||||
// Size
|
||||
SL_LIST_TEMPLATE_LIST
|
||||
int32
|
||||
SL_LIST_CLASS_NAME::Size() const
|
||||
{
|
||||
int32 count = 0;
|
||||
for (Element* element = GetFirst(); element; element = GetNext(element))
|
||||
count++;
|
||||
return count;
|
||||
}
|
||||
|
||||
#endif // SL_LIST_H
|
@ -10,7 +10,6 @@
|
||||
#include "FSCapabilities.h"
|
||||
#include "LazyInitializable.h"
|
||||
#include "Locker.h"
|
||||
#include "Referencable.h"
|
||||
#include "RequestPort.h"
|
||||
#include "RequestPortPool.h"
|
||||
#include "String.h"
|
||||
|
@ -5,8 +5,9 @@
|
||||
#ifndef USERLAND_FS_FILE_SYSTEM_INITIALIZER_H
|
||||
#define USERLAND_FS_FILE_SYSTEM_INITIALIZER_H
|
||||
|
||||
#include <Referenceable.h>
|
||||
|
||||
#include "LazyInitializable.h"
|
||||
#include "Referencable.h"
|
||||
|
||||
|
||||
namespace UserlandFSUtil {
|
||||
@ -19,7 +20,7 @@ using UserlandFSUtil::RequestPort;
|
||||
|
||||
class FileSystem;
|
||||
|
||||
class FileSystemInitializer : public LazyInitializable, public Referencable {
|
||||
class FileSystemInitializer : public LazyInitializable, public Referenceable {
|
||||
public:
|
||||
FileSystemInitializer(const char* name);
|
||||
~FileSystemInitializer();
|
||||
|
@ -4,6 +4,7 @@ local userlandFSTop = [ FDirName $(HAIKU_TOP) src add-ons kernel file_systems
|
||||
userlandfs ] ;
|
||||
local userlandFSIncludes = [ PrivateHeaders userlandfs ] ;
|
||||
|
||||
UsePrivateHeaders shared ;
|
||||
UsePrivateKernelHeaders ;
|
||||
SubDirHdrs [ FDirName $(userlandFSIncludes) private ] ;
|
||||
SubDirHdrs [ FDirName $(userlandFSIncludes) shared ] ;
|
||||
@ -20,7 +21,6 @@ KernelAddon userlandfs
|
||||
Locker.cpp
|
||||
ObjectTracker.cpp
|
||||
Port.cpp
|
||||
Referencable.cpp
|
||||
Request.cpp
|
||||
RequestAllocator.cpp
|
||||
RequestHandler.cpp
|
||||
|
@ -71,7 +71,7 @@ private:
|
||||
|
||||
// constructor
|
||||
Volume::Volume(FileSystem* fileSystem, fs_volume* fsVolume)
|
||||
: Referencable(true),
|
||||
: Referenceable(true),
|
||||
fFileSystem(fileSystem),
|
||||
fFSVolume(fsVolume),
|
||||
fUserlandVolume(NULL),
|
||||
|
@ -7,8 +7,9 @@
|
||||
|
||||
#include <fs_interface.h>
|
||||
|
||||
#include <Referenceable.h>
|
||||
|
||||
#include "FSCapabilities.h"
|
||||
#include "Referencable.h"
|
||||
|
||||
namespace UserlandFSUtil {
|
||||
|
||||
@ -29,7 +30,7 @@ using UserlandFSUtil::userlandfs_ioctl;
|
||||
|
||||
class FileSystem;
|
||||
|
||||
class Volume : public Referencable {
|
||||
class Volume : public Referenceable {
|
||||
public:
|
||||
Volume(FileSystem* fileSystem,
|
||||
fs_volume* fsVolume);
|
||||
|
@ -5,7 +5,7 @@ local userlandFSTop = [ FDirName $(HAIKU_TOP) src add-ons kernel
|
||||
local userlandFSIncludes = [ PrivateHeaders userlandfs ] ;
|
||||
|
||||
SubDirSysHdrs [ FDirName $(userlandFSIncludes) ] ;
|
||||
UsePrivateHeaders libroot ;
|
||||
UsePrivateHeaders kernel libroot shared ;
|
||||
SubDirHdrs [ FDirName $(userlandFSIncludes) private ] ;
|
||||
SubDirHdrs [ FDirName $(userlandFSIncludes) shared ] ;
|
||||
|
||||
@ -25,7 +25,6 @@ Application userlandfs_server
|
||||
Locker.cpp
|
||||
ObjectTracker.cpp
|
||||
Port.cpp
|
||||
Referencable.cpp
|
||||
Request.cpp
|
||||
RequestAllocator.cpp
|
||||
RequestHandler.cpp
|
||||
|
@ -9,7 +9,7 @@ SubDirHdrs [ FDirName $(userlandFSIncludes) private ] ;
|
||||
SubDirHdrs [ FDirName $(userlandFSIncludes) shared ] ;
|
||||
|
||||
UsePrivateSystemHeaders ;
|
||||
UsePrivateHeaders libroot ;
|
||||
UsePrivateHeaders libroot shared ;
|
||||
|
||||
SEARCH_SOURCE += [ FDirName $(userlandFSTop) private ] ;
|
||||
SEARCH_SOURCE += [ FDirName $(userlandFSTop) shared ] ;
|
||||
|
@ -6,8 +6,9 @@
|
||||
|
||||
#include <driver_settings.h>
|
||||
|
||||
#include <Referenceable.h>
|
||||
|
||||
#include "DriverSettings.h"
|
||||
#include "Referencable.h"
|
||||
#include "String.h"
|
||||
|
||||
// The parameter values that shall be evaluated to true.
|
||||
@ -21,9 +22,9 @@ static const int32 kTrueValueStringCount
|
||||
// #pragma mark ----- DriverParameterIterator -----
|
||||
|
||||
// Delegate
|
||||
class DriverParameterIterator::Delegate : public Referencable {
|
||||
class DriverParameterIterator::Delegate : public Referenceable {
|
||||
public:
|
||||
Delegate() : Referencable(true) {}
|
||||
Delegate() : Referenceable(true) {}
|
||||
virtual ~Delegate() {}
|
||||
|
||||
virtual Delegate* Clone() const = 0;
|
||||
@ -222,7 +223,7 @@ DriverParameterContainer::CountParameters() const
|
||||
{
|
||||
int32 count;
|
||||
return (GetParametersAndCount(&count) ? count : 0);
|
||||
|
||||
|
||||
}
|
||||
|
||||
// GetParameters
|
||||
|
@ -3,7 +3,8 @@
|
||||
#include <new>
|
||||
#include <typeinfo>
|
||||
|
||||
#include "AutoLocker.h"
|
||||
#include <AutoLocker.h>
|
||||
|
||||
#include "Debug.h"
|
||||
#include "ObjectTracker.h"
|
||||
|
||||
@ -34,7 +35,7 @@ ObjectTracker::ObjectTracker()
|
||||
// destructor
|
||||
ObjectTracker::~ObjectTracker()
|
||||
{
|
||||
ObjectTrackable* trackable = fTrackables.GetFirst();
|
||||
ObjectTrackable* trackable = fTrackables.First();
|
||||
if (trackable) {
|
||||
WARN(("ObjectTracker: WARNING: There are still undeleted objects:\n"));
|
||||
for (; trackable; trackable = fTrackables.GetNext(trackable)) {
|
||||
|
@ -1,41 +0,0 @@
|
||||
// Referencable.cpp
|
||||
|
||||
#include "Debug.h"
|
||||
#include "Referencable.h"
|
||||
|
||||
// constructor
|
||||
Referencable::Referencable(bool deleteWhenUnreferenced)
|
||||
: fReferenceCount(1),
|
||||
fDeleteWhenUnreferenced(deleteWhenUnreferenced)
|
||||
{
|
||||
}
|
||||
|
||||
// destructor
|
||||
Referencable::~Referencable()
|
||||
{
|
||||
}
|
||||
|
||||
// AddReference
|
||||
void
|
||||
Referencable::AddReference()
|
||||
{
|
||||
atomic_add(&fReferenceCount, 1);
|
||||
}
|
||||
|
||||
// RemoveReference
|
||||
bool
|
||||
Referencable::RemoveReference()
|
||||
{
|
||||
bool unreferenced = (atomic_add(&fReferenceCount, -1) == 1);
|
||||
if (fDeleteWhenUnreferenced && unreferenced)
|
||||
delete this;
|
||||
return unreferenced;
|
||||
}
|
||||
|
||||
// CountReferences
|
||||
int32
|
||||
Referencable::CountReferences() const
|
||||
{
|
||||
return fReferenceCount;
|
||||
}
|
||||
|
Loading…
x
Reference in New Issue
Block a user