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:
@@ -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
|
} // namespace BPrivate
|
||||||
|
|
||||||
using BPrivate::BWeakReferenceable;
|
using BPrivate::BWeakReferenceable;
|
||||||
|
|||||||
@@ -67,6 +67,7 @@ for architectureObject in [ MultiArchSubDirSetup ] {
|
|||||||
Thread.cpp
|
Thread.cpp
|
||||||
ToolBar.cpp
|
ToolBar.cpp
|
||||||
Variant.cpp
|
Variant.cpp
|
||||||
|
WeakReferenceable.cpp
|
||||||
;
|
;
|
||||||
|
|
||||||
Includes [ FGristFiles Keymap.cpp ]
|
Includes [ FGristFiles Keymap.cpp ]
|
||||||
|
|||||||
@@ -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
|
||||||
@@ -147,11 +147,15 @@ SEARCH on [ FGristFiles $(muslSources) ] += [ FDirName $(posixSources) musl misc
|
|||||||
|
|
||||||
# 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 :
|
KernelMergeObject kernel_misc.o :
|
||||||
DataIO.cpp
|
DataIO.cpp
|
||||||
Referenceable.cpp
|
Referenceable.cpp
|
||||||
|
WeakReferenceable.cpp
|
||||||
|
|
||||||
: $(TARGET_KERNEL_PIC_CCFLAGS)
|
: $(TARGET_KERNEL_PIC_CCFLAGS)
|
||||||
;
|
;
|
||||||
|
|||||||
Reference in New Issue
Block a user