BPrivate::WeakReferenceable: Move implementation to a .cpp.

No functional change to the implementation, just getting it
out of a header.
This commit is contained in:
Augustin Cavalier
2023-01-31 15:36:15 -05:00
parent da49d61cb7
commit 1e860e07ee
4 changed files with 106 additions and 94 deletions
@@ -230,99 +230,6 @@ private:
};
// #pragma mark -
inline
WeakPointer::WeakPointer(BWeakReferenceable* object)
:
fUseCount(1),
fObject(object)
{
}
inline
WeakPointer::~WeakPointer()
{
}
inline BWeakReferenceable*
WeakPointer::Get()
{
int32 count = -11;
do {
count = atomic_get(&fUseCount);
if (count == 0)
return NULL;
} while (atomic_test_and_set(&fUseCount, count + 1, count) != count);
return fObject;
}
inline bool
WeakPointer::Put()
{
if (atomic_add(&fUseCount, -1) == 1) {
delete fObject;
return true;
}
return false;
}
inline int32
WeakPointer::UseCount() const
{
return fUseCount;
}
inline void
WeakPointer::GetUnchecked()
{
atomic_add(&fUseCount, 1);
}
// #pragma -
inline
BWeakReferenceable::BWeakReferenceable()
:
fPointer(new(std::nothrow) WeakPointer(this))
{
}
inline
BWeakReferenceable::~BWeakReferenceable()
{
fPointer->ReleaseReference();
}
inline status_t
BWeakReferenceable::InitCheck()
{
if (fPointer == NULL)
return B_NO_MEMORY;
return B_OK;
}
inline WeakPointer*
BWeakReferenceable::GetWeakPointer()
{
fPointer->AcquireReference();
return fPointer;
}
} // namespace BPrivate
using BPrivate::BWeakReferenceable;
+1
View File
@@ -67,6 +67,7 @@ for architectureObject in [ MultiArchSubDirSetup ] {
Thread.cpp
ToolBar.cpp
Variant.cpp
WeakReferenceable.cpp
;
Includes [ FGristFiles Keymap.cpp ]
+100
View File
@@ -0,0 +1,100 @@
/*
* Copyright 2009, Axel Dörfler, [email protected].
* Distributed under the terms of the MIT License.
*/
#include <WeakReferenceable.h>
namespace BPrivate {
WeakPointer::WeakPointer(BWeakReferenceable* object)
:
fUseCount(1),
fObject(object)
{
}
WeakPointer::~WeakPointer()
{
}
BWeakReferenceable*
WeakPointer::Get()
{
int32 count = -11;
do {
count = atomic_get(&fUseCount);
if (count == 0)
return NULL;
} while (atomic_test_and_set(&fUseCount, count + 1, count) != count);
return fObject;
}
bool
WeakPointer::Put()
{
if (atomic_add(&fUseCount, -1) == 1) {
delete fObject;
return true;
}
return false;
}
int32
WeakPointer::UseCount() const
{
return fUseCount;
}
void
WeakPointer::GetUnchecked()
{
atomic_add(&fUseCount, 1);
}
// #pragma -
BWeakReferenceable::BWeakReferenceable()
:
fPointer(new(std::nothrow) WeakPointer(this))
{
}
BWeakReferenceable::~BWeakReferenceable()
{
fPointer->ReleaseReference();
}
status_t
BWeakReferenceable::InitCheck()
{
if (fPointer == NULL)
return B_NO_MEMORY;
return B_OK;
}
WeakPointer*
BWeakReferenceable::GetWeakPointer()
{
fPointer->AcquireReference();
return fPointer;
}
} // namespace BPrivate
+5 -1
View File
@@ -147,11 +147,15 @@ SEARCH on [ FGristFiles $(muslSources) ] += [ FDirName $(posixSources) musl misc
# misc
SEARCH_SOURCE = [ FDirName $(HAIKU_TOP) src kits support ] ;
SEARCH_SOURCE =
[ FDirName $(HAIKU_TOP) src kits support ]
[ FDirName $(HAIKU_TOP) src kits shared ]
;
KernelMergeObject kernel_misc.o :
DataIO.cpp
Referenceable.cpp
WeakReferenceable.cpp
: $(TARGET_KERNEL_PIC_CCFLAGS)
;