From 756b64fd836dad5b63f41f0b01f8cedfec795f9d Mon Sep 17 00:00:00 2001 From: Ingo Weinhold Date: Thu, 16 Dec 2010 16:35:42 +0000 Subject: [PATCH] * 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 --- headers/private/shared/Referenceable.h | 133 +----------------- headers/private/shared/WeakReferenceable.h | 14 +- .../kernel/network/stack/net_socket.cpp | 12 +- .../mediaplayer/playlist/PLItemsCommand.cpp | 2 +- src/apps/mediaplayer/playlist/Playlist.cpp | 2 +- src/apps/powerstatus/DriverInterface.h | 2 +- src/apps/showimage/ImageCache.h | 2 +- src/bin/debug/profile/Image.cpp | 4 +- src/bin/debug/profile/Image.h | 2 +- src/bin/debug/profile/ProfileResult.cpp | 4 +- src/bin/debug/profile/SharedImage.h | 2 +- src/bin/debug/profile/Team.cpp | 4 +- src/bin/debug/profile/profile.cpp | 2 +- src/kits/support/Referenceable.cpp | 8 +- src/servers/app/FontCache.cpp | 10 +- src/servers/app/ServerPicture.cpp | 4 +- src/servers/registrar/MessageDeliverer.cpp | 10 +- 17 files changed, 47 insertions(+), 170 deletions(-) diff --git a/headers/private/shared/Referenceable.h b/headers/private/shared/Referenceable.h index d83923bc0f..264eaea6ea 100644 --- a/headers/private/shared/Referenceable.h +++ b/headers/private/shared/Referenceable.h @@ -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 +// #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 class BReference { public: @@ -145,107 +127,4 @@ private: }; -// #pragma mark Obsolete API - -// TODO: To be phased out! - - -namespace BPrivate { - - -// Reference -template -class Reference { -public: - Reference() - : fObject(NULL) - { - } - - Reference(Type* object, bool alreadyHasReference = false) - : fObject(NULL) - { - SetTo(object, alreadyHasReference); - } - - Reference(const Reference& 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& other) - { - SetTo(other.fObject); - return *this; - } - - bool operator==(const Reference& other) const - { - return (fObject == other.fObject); - } - - bool operator!=(const Reference& other) const - { - return (fObject != other.fObject); - } - -private: - Type* fObject; -}; - - -typedef BReferenceable Referenceable; - -} // namespace BPrivate - -using BPrivate::Referenceable; -using BPrivate::Reference; - - #endif // _REFERENCEABLE_H diff --git a/headers/private/shared/WeakReferenceable.h b/headers/private/shared/WeakReferenceable.h index af5a997688..b0182688dd 100644 --- a/headers/private/shared/WeakReferenceable.h +++ b/headers/private/shared/WeakReferenceable.h @@ -14,7 +14,7 @@ namespace BPrivate { template class WeakReferenceable; template -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 inline WeakReferenceable::~WeakReferenceable() { - fPointer->RemoveReference(); + fPointer->ReleaseReference(); } @@ -295,7 +295,7 @@ template inline WeakPointer* WeakReferenceable::GetWeakPointer() { - fPointer->AddReference(); + fPointer->AcquireReference(); return fPointer; } diff --git a/src/add-ons/kernel/network/stack/net_socket.cpp b/src/add-ons/kernel/network/stack/net_socket.cpp index 608a5a6f96..f2b99da1bb 100644 --- a/src/add-ons/kernel/network/stack/net_socket.cpp +++ b/src/add-ons/kernel/network/stack/net_socket.cpp @@ -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; diff --git a/src/apps/mediaplayer/playlist/PLItemsCommand.cpp b/src/apps/mediaplayer/playlist/PLItemsCommand.cpp index 0e842bd765..455b86741f 100644 --- a/src/apps/mediaplayer/playlist/PLItemsCommand.cpp +++ b/src/apps/mediaplayer/playlist/PLItemsCommand.cpp @@ -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; diff --git a/src/apps/mediaplayer/playlist/Playlist.cpp b/src/apps/mediaplayer/playlist/Playlist.cpp index e55760c60a..0b146fad29 100644 --- a/src/apps/mediaplayer/playlist/Playlist.cpp +++ b/src/apps/mediaplayer/playlist/Playlist.cpp @@ -235,7 +235,7 @@ Playlist::MakeEmpty(bool deleteItems) PlaylistItem* item = RemoveItem(i, false); _NotifyItemRemoved(i); if (deleteItems) - item->RemoveReference(); + item->ReleaseReference(); } SetCurrentItemIndex(-1); } diff --git a/src/apps/powerstatus/DriverInterface.h b/src/apps/powerstatus/DriverInterface.h index 44b3351d66..52194b68e8 100644 --- a/src/apps/powerstatus/DriverInterface.h +++ b/src/apps/powerstatus/DriverInterface.h @@ -46,7 +46,7 @@ protected: }; -class PowerStatusDriverInterface : public Monitor, public Referenceable { +class PowerStatusDriverInterface : public Monitor, public BReferenceable { public: PowerStatusDriverInterface(); ~PowerStatusDriverInterface(); diff --git a/src/apps/showimage/ImageCache.h b/src/apps/showimage/ImageCache.h index 58b1e39e91..000fa95ff2 100644 --- a/src/apps/showimage/ImageCache.h +++ b/src/apps/showimage/ImageCache.h @@ -30,7 +30,7 @@ enum { }; -class BitmapOwner : public Referenceable { +class BitmapOwner : public BReferenceable { public: BitmapOwner(BBitmap* bitmap); virtual ~BitmapOwner(); diff --git a/src/bin/debug/profile/Image.cpp b/src/bin/debug/profile/Image.cpp index 3e93b6262d..656075a741 100644 --- a/src/bin/debug/profile/Image.cpp +++ b/src/bin/debug/profile/Image.cpp @@ -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(); } diff --git a/src/bin/debug/profile/Image.h b/src/bin/debug/profile/Image.h index 1e6af5c0d0..d9c61e157f 100644 --- a/src/bin/debug/profile/Image.h +++ b/src/bin/debug/profile/Image.h @@ -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, diff --git a/src/bin/debug/profile/ProfileResult.cpp b/src/bin/debug/profile/ProfileResult.cpp index 5d81a40bb2..1f393cb5aa 100644 --- a/src/bin/debug/profile/ProfileResult.cpp +++ b/src/bin/debug/profile/ProfileResult.cpp @@ -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(); } diff --git a/src/bin/debug/profile/SharedImage.h b/src/bin/debug/profile/SharedImage.h index 38a2ab0a85..1afa03b72d 100644 --- a/src/bin/debug/profile/SharedImage.h +++ b/src/bin/debug/profile/SharedImage.h @@ -45,7 +45,7 @@ struct SymbolComparator { }; -class SharedImage : public Referenceable { +class SharedImage : public BReferenceable { public: SharedImage(); ~SharedImage(); diff --git a/src/bin/debug/profile/Team.cpp b/src/bin/debug/profile/Team.cpp index 65e5cfe74c..331b28e9dd 100644 --- a/src/bin/debug/profile/Team.cpp +++ b/src/bin/debug/profile/Team.cpp @@ -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(); } diff --git a/src/bin/debug/profile/profile.cpp b/src/bin/debug/profile/profile.cpp index 377644ab8c..0878237c07 100644 --- a/src/bin/debug/profile/profile.cpp +++ b/src/bin/debug/profile/profile.cpp @@ -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(); diff --git a/src/kits/support/Referenceable.cpp b/src/kits/support/Referenceable.cpp index 9c6fa15550..3df724635e 100644 --- a/src/kits/support/Referenceable.cpp +++ b/src/kits/support/Referenceable.cpp @@ -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; } diff --git a/src/servers/app/FontCache.cpp b/src/servers/app/FontCache.cpp index c27b153a47..52baa53899 100644 --- a/src/servers/app/FontCache.cpp +++ b/src/servers/app/FontCache.cpp @@ -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; } } diff --git a/src/servers/app/ServerPicture.cpp b/src/servers/app/ServerPicture.cpp index 05746503f7..e0c19837c3 100644 --- a/src/servers/app/ServerPicture.cpp +++ b/src/servers/app/ServerPicture.cpp @@ -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 _(this); + BReference _(this); if (fOwner != NULL) fOwner->RemovePicture(this); diff --git a/src/servers/registrar/MessageDeliverer.cpp b/src/servers/registrar/MessageDeliverer.cpp index b382d73131..1b383f2d7b 100644 --- a/src/servers/registrar/MessageDeliverer.cpp +++ b/src/servers/registrar/MessageDeliverer.cpp @@ -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, true); + BReference _(message, true); // add the message to the respective target ports BAutolock locker(fLock);