* Removed the obsolescent [B]Reference[able] API and replaced the remaining
uses. Fixes the gcc 2 acpi build. * Renamed WeakReferenceable::{Add,Remove}Reference() to {Acquire,Release}Reference() for consistency. git-svn-id: file:///srv/svn/repos/haiku/haiku/trunk@39871 a95241bf-73f2-0310-859d-f6bbb57e9c96
This commit is contained in:
parent
88e38c178a
commit
756b64fd83
@ -1,5 +1,5 @@
|
||||
/*
|
||||
* Copyright 2004-2009, Ingo Weinhold, ingo_weinhold@gmx.de.
|
||||
* Copyright 2004-2010, Ingo Weinhold, ingo_weinhold@gmx.de.
|
||||
* Distributed under the terms of the MIT License.
|
||||
*/
|
||||
#ifndef _REFERENCEABLE_H
|
||||
@ -9,13 +9,12 @@
|
||||
#include <SupportDefs.h>
|
||||
|
||||
|
||||
// #pragma mark - BReferenceable
|
||||
|
||||
|
||||
class BReferenceable {
|
||||
public:
|
||||
BReferenceable(
|
||||
bool deleteWhenUnreferenced = true);
|
||||
// TODO: The parameter is deprecated.
|
||||
// Override LastReferenceReleased()
|
||||
// instead!
|
||||
BReferenceable();
|
||||
virtual ~BReferenceable();
|
||||
|
||||
void AcquireReference();
|
||||
@ -25,35 +24,18 @@ public:
|
||||
int32 CountReferences() const
|
||||
{ return fReferenceCount; }
|
||||
|
||||
// deprecate aliases
|
||||
inline void AddReference();
|
||||
inline bool RemoveReference();
|
||||
|
||||
protected:
|
||||
virtual void FirstReferenceAcquired();
|
||||
virtual void LastReferenceReleased();
|
||||
|
||||
protected:
|
||||
vint32 fReferenceCount;
|
||||
bool fDeleteWhenUnreferenced;
|
||||
};
|
||||
|
||||
|
||||
void
|
||||
BReferenceable::AddReference()
|
||||
{
|
||||
AcquireReference();
|
||||
}
|
||||
// #pragma mark - BReference
|
||||
|
||||
|
||||
bool
|
||||
BReferenceable::RemoveReference()
|
||||
{
|
||||
return ReleaseReference();
|
||||
}
|
||||
|
||||
|
||||
// BReference
|
||||
template<typename Type = BReferenceable>
|
||||
class BReference {
|
||||
public:
|
||||
@ -145,107 +127,4 @@ private:
|
||||
};
|
||||
|
||||
|
||||
// #pragma mark Obsolete API
|
||||
|
||||
// TODO: To be phased out!
|
||||
|
||||
|
||||
namespace BPrivate {
|
||||
|
||||
|
||||
// Reference
|
||||
template<typename Type = BReferenceable>
|
||||
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)
|
||||
{
|
||||
if (object != NULL && !alreadyHasReference)
|
||||
object->AddReference();
|
||||
|
||||
Unset();
|
||||
|
||||
fObject = object;
|
||||
}
|
||||
|
||||
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;
|
||||
};
|
||||
|
||||
|
||||
typedef BReferenceable Referenceable;
|
||||
|
||||
} // namespace BPrivate
|
||||
|
||||
using BPrivate::Referenceable;
|
||||
using BPrivate::Reference;
|
||||
|
||||
|
||||
#endif // _REFERENCEABLE_H
|
||||
|
@ -14,7 +14,7 @@ namespace BPrivate {
|
||||
template<typename Type> class WeakReferenceable;
|
||||
|
||||
template<typename Type>
|
||||
class WeakPointer : public Referenceable {
|
||||
class WeakPointer : public BReferenceable {
|
||||
public:
|
||||
Type* Get();
|
||||
bool Put();
|
||||
@ -41,10 +41,10 @@ public:
|
||||
WeakReferenceable(Type* object);
|
||||
~WeakReferenceable();
|
||||
|
||||
void AddReference()
|
||||
void AcquireReference()
|
||||
{ fPointer->_GetUnchecked(); }
|
||||
|
||||
bool RemoveReference()
|
||||
bool ReleaseReference()
|
||||
{ return fPointer->Put(); }
|
||||
|
||||
int32 CountReferences() const
|
||||
@ -119,7 +119,7 @@ public:
|
||||
|
||||
if (pointer != NULL) {
|
||||
fPointer = pointer;
|
||||
fPointer->AddReference();
|
||||
fPointer->AcquireReference();
|
||||
fObject = pointer->Get();
|
||||
}
|
||||
}
|
||||
@ -131,7 +131,7 @@ public:
|
||||
fPointer->Put();
|
||||
fObject = NULL;
|
||||
}
|
||||
fPointer->RemoveReference();
|
||||
fPointer->ReleaseReference();
|
||||
fPointer = NULL;
|
||||
}
|
||||
}
|
||||
@ -287,7 +287,7 @@ template<typename Type>
|
||||
inline
|
||||
WeakReferenceable<Type>::~WeakReferenceable()
|
||||
{
|
||||
fPointer->RemoveReference();
|
||||
fPointer->ReleaseReference();
|
||||
}
|
||||
|
||||
|
||||
@ -295,7 +295,7 @@ template<typename Type>
|
||||
inline WeakPointer<Type>*
|
||||
WeakReferenceable<Type>::GetWeakPointer()
|
||||
{
|
||||
fPointer->AddReference();
|
||||
fPointer->AcquireReference();
|
||||
return fPointer;
|
||||
}
|
||||
|
||||
|
@ -148,7 +148,7 @@ net_socket_private::RemoveFromParent()
|
||||
{
|
||||
ASSERT(!is_in_socket_list && parent != NULL);
|
||||
|
||||
parent->RemoveReference();
|
||||
parent->ReleaseReference();
|
||||
parent = NULL;
|
||||
|
||||
mutex_lock(&sSocketLock);
|
||||
@ -157,7 +157,7 @@ net_socket_private::RemoveFromParent()
|
||||
|
||||
is_in_socket_list = true;
|
||||
|
||||
RemoveReference();
|
||||
ReleaseReference();
|
||||
}
|
||||
|
||||
|
||||
@ -458,7 +458,7 @@ socket_free(net_socket* _socket)
|
||||
{
|
||||
net_socket_private* socket = (net_socket_private*)_socket;
|
||||
socket->first_info->free(socket->first_protocol);
|
||||
socket->RemoveReference();
|
||||
socket->ReleaseReference();
|
||||
}
|
||||
|
||||
|
||||
@ -674,7 +674,7 @@ socket_acquire(net_socket* _socket)
|
||||
if (socket->CountReferences() == 0)
|
||||
return false;
|
||||
|
||||
socket->AddReference();
|
||||
socket->AcquireReference();
|
||||
return true;
|
||||
}
|
||||
|
||||
@ -683,7 +683,7 @@ bool
|
||||
socket_release(net_socket* _socket)
|
||||
{
|
||||
net_socket_private* socket = (net_socket_private*)_socket;
|
||||
return socket->RemoveReference();
|
||||
return socket->ReleaseReference();
|
||||
}
|
||||
|
||||
|
||||
@ -739,7 +739,7 @@ socket_dequeue_connected(net_socket* _parent, net_socket** _socket)
|
||||
|
||||
net_socket_private* socket = parent->connected_children.RemoveHead();
|
||||
if (socket != NULL) {
|
||||
socket->AddReference();
|
||||
socket->AcquireReference();
|
||||
socket->RemoveFromParent();
|
||||
parent->child_count--;
|
||||
*_socket = socket;
|
||||
|
@ -35,7 +35,7 @@ PLItemsCommand::_CleanUp(PlaylistItem**& items, int32 count, bool deleteItems)
|
||||
return;
|
||||
if (deleteItems) {
|
||||
for (int32 i = 0; i < count; i++)
|
||||
items[i]->RemoveReference();
|
||||
items[i]->ReleaseReference();
|
||||
}
|
||||
delete[] items;
|
||||
items = NULL;
|
||||
|
@ -235,7 +235,7 @@ Playlist::MakeEmpty(bool deleteItems)
|
||||
PlaylistItem* item = RemoveItem(i, false);
|
||||
_NotifyItemRemoved(i);
|
||||
if (deleteItems)
|
||||
item->RemoveReference();
|
||||
item->ReleaseReference();
|
||||
}
|
||||
SetCurrentItemIndex(-1);
|
||||
}
|
||||
|
@ -46,7 +46,7 @@ protected:
|
||||
};
|
||||
|
||||
|
||||
class PowerStatusDriverInterface : public Monitor, public Referenceable {
|
||||
class PowerStatusDriverInterface : public Monitor, public BReferenceable {
|
||||
public:
|
||||
PowerStatusDriverInterface();
|
||||
~PowerStatusDriverInterface();
|
||||
|
@ -30,7 +30,7 @@ enum {
|
||||
};
|
||||
|
||||
|
||||
class BitmapOwner : public Referenceable {
|
||||
class BitmapOwner : public BReferenceable {
|
||||
public:
|
||||
BitmapOwner(BBitmap* bitmap);
|
||||
virtual ~BitmapOwner();
|
||||
|
@ -16,11 +16,11 @@ Image::Image(SharedImage* image, const image_info& info, team_id owner,
|
||||
fCreationEvent(creationEvent),
|
||||
fDeletionEvent(-1)
|
||||
{
|
||||
fImage->AddReference();
|
||||
fImage->AcquireReference();
|
||||
}
|
||||
|
||||
|
||||
Image::~Image()
|
||||
{
|
||||
fImage->RemoveReference();
|
||||
fImage->ReleaseReference();
|
||||
}
|
||||
|
@ -8,7 +8,7 @@
|
||||
#include "SharedImage.h"
|
||||
|
||||
|
||||
class Image : public Referenceable {
|
||||
class Image : public BReferenceable {
|
||||
public:
|
||||
Image(SharedImage* image,
|
||||
const image_info& info, team_id owner,
|
||||
|
@ -32,13 +32,13 @@ ImageProfileResult::ImageProfileResult(SharedImage* image, image_id id)
|
||||
fTotalHits(0),
|
||||
fImageID(id)
|
||||
{
|
||||
fImage->AddReference();
|
||||
fImage->AcquireReference();
|
||||
}
|
||||
|
||||
|
||||
ImageProfileResult::~ImageProfileResult()
|
||||
{
|
||||
fImage->RemoveReference();
|
||||
fImage->ReleaseReference();
|
||||
}
|
||||
|
||||
|
||||
|
@ -45,7 +45,7 @@ struct SymbolComparator {
|
||||
};
|
||||
|
||||
|
||||
class SharedImage : public Referenceable {
|
||||
class SharedImage : public BReferenceable {
|
||||
public:
|
||||
SharedImage();
|
||||
~SharedImage();
|
||||
|
@ -51,7 +51,7 @@ Team::~Team()
|
||||
remove_team_debugger(fID);
|
||||
|
||||
for (int32 i = 0; Image* image = fImages.ItemAt(i); i++)
|
||||
image->RemoveReference();
|
||||
image->ReleaseReference();
|
||||
}
|
||||
|
||||
|
||||
@ -277,5 +277,5 @@ Team::_RemoveImage(int32 index, int32 event)
|
||||
}
|
||||
|
||||
image->SetDeletionEvent(event);
|
||||
image->RemoveReference();
|
||||
image->ReleaseReference();
|
||||
}
|
||||
|
@ -113,7 +113,7 @@ public:
|
||||
{
|
||||
// release image references
|
||||
for (ImageMap::iterator it = fImages.begin(); it != fImages.end(); ++it)
|
||||
it->second->RemoveReference();
|
||||
it->second->ReleaseReference();
|
||||
|
||||
if (fSummaryProfileResult != NULL)
|
||||
fSummaryProfileResult->ReleaseReference();
|
||||
|
@ -16,10 +16,9 @@
|
||||
#endif
|
||||
|
||||
|
||||
BReferenceable::BReferenceable(bool deleteWhenUnreferenced)
|
||||
BReferenceable::BReferenceable()
|
||||
:
|
||||
fReferenceCount(1),
|
||||
fDeleteWhenUnreferenced(deleteWhenUnreferenced)
|
||||
fReferenceCount(1)
|
||||
{
|
||||
}
|
||||
|
||||
@ -59,6 +58,5 @@ BReferenceable::FirstReferenceAcquired()
|
||||
void
|
||||
BReferenceable::LastReferenceReleased()
|
||||
{
|
||||
if (fDeleteWhenUnreferenced)
|
||||
delete this;
|
||||
delete this;
|
||||
}
|
||||
|
@ -38,7 +38,7 @@ FontCache::~FontCache()
|
||||
{
|
||||
FontMap::Iterator iterator = fFontCacheEntries.GetIterator();
|
||||
while (iterator.HasNext())
|
||||
iterator.Next().value->RemoveReference();
|
||||
iterator.Next().value->ReleaseReference();
|
||||
}
|
||||
|
||||
// Default
|
||||
@ -62,7 +62,7 @@ FontCache::FontCacheEntryFor(const ServerFont& font)
|
||||
|
||||
if (entry) {
|
||||
// the entry was already there
|
||||
entry->AddReference();
|
||||
entry->AcquireReference();
|
||||
//printf("FontCacheEntryFor(%ld): %p\n", font.GetFamilyAndStyle(), entry);
|
||||
return entry;
|
||||
}
|
||||
@ -95,7 +95,7 @@ FontCache::FontCacheEntryFor(const ServerFont& font)
|
||||
}
|
||||
//printf("FontCacheEntryFor(%ld): %p (insert)\n", font.GetFamilyAndStyle(), entry);
|
||||
|
||||
entry->AddReference();
|
||||
entry->AcquireReference();
|
||||
return entry;
|
||||
}
|
||||
|
||||
@ -107,7 +107,7 @@ FontCache::Recycle(FontCacheEntry* entry)
|
||||
if (!entry)
|
||||
return;
|
||||
entry->UpdateUsage();
|
||||
entry->RemoveReference();
|
||||
entry->ReleaseReference();
|
||||
}
|
||||
|
||||
static const int32 kMaxEntryCount = 30;
|
||||
@ -154,7 +154,7 @@ FontCache::_ConstrainEntryCount()
|
||||
while (iterator.HasNext()) {
|
||||
if (iterator.Next().value == leastUsedEntry) {
|
||||
iterator.Remove();
|
||||
leastUsedEntry->RemoveReference();
|
||||
leastUsedEntry->ReleaseReference();
|
||||
break;
|
||||
}
|
||||
}
|
||||
|
@ -920,7 +920,7 @@ ServerPicture::~ServerPicture()
|
||||
|
||||
delete fPictures;
|
||||
}
|
||||
|
||||
|
||||
if (fPushed != NULL) {
|
||||
fPushed->SetOwner(NULL);
|
||||
fPushed->ReleaseReference();
|
||||
@ -938,7 +938,7 @@ ServerPicture::SetOwner(ServerApp* owner)
|
||||
// May remove the last reference and then we will self-destruct right then.
|
||||
// Setting fOwner to NULL would access free'd memory. If owner is another
|
||||
// ServerApp, it's expected to already have a reference of course.
|
||||
Reference<ServerPicture> _(this);
|
||||
BReference<ServerPicture> _(this);
|
||||
|
||||
if (fOwner != NULL)
|
||||
fOwner->RemovePicture(this);
|
||||
|
@ -159,10 +159,10 @@ SingleMessagingTargetSet::Rewind()
|
||||
Besides the flattened message it also stores the when the message was
|
||||
created and when the delivery attempts shall time out.
|
||||
*/
|
||||
class MessageDeliverer::Message : public Referenceable {
|
||||
class MessageDeliverer::Message : public BReferenceable {
|
||||
public:
|
||||
Message(void *data, int32 dataSize, bigtime_t timeout)
|
||||
: Referenceable(true),
|
||||
: BReferenceable(),
|
||||
fData(data),
|
||||
fDataSize(dataSize),
|
||||
fCreationTime(system_time()),
|
||||
@ -243,13 +243,13 @@ public:
|
||||
fToken(token)
|
||||
{
|
||||
if (fMessage)
|
||||
fMessage->AddReference();
|
||||
fMessage->AcquireReference();
|
||||
}
|
||||
|
||||
~TargetMessage()
|
||||
{
|
||||
if (fMessage)
|
||||
fMessage->RemoveReference();
|
||||
fMessage->ReleaseReference();
|
||||
}
|
||||
|
||||
Message *GetMessage() const
|
||||
@ -653,7 +653,7 @@ MessageDeliverer::DeliverMessage(const void *messageData, int32 messageSize,
|
||||
free(data);
|
||||
return B_NO_MEMORY;
|
||||
}
|
||||
Reference<Message> _(message, true);
|
||||
BReference<Message> _(message, true);
|
||||
|
||||
// add the message to the respective target ports
|
||||
BAutolock locker(fLock);
|
||||
|
Loading…
Reference in New Issue
Block a user