app_server: Rework ClonedAreaMemory to use ServerMemoryAllocator.
This takes advantage of the new reference (use)-counting logic inside ServerMemoryAllocator to not re-clone areas needlessly. Fixes #8501.
This commit is contained in:
@@ -26,6 +26,7 @@
|
|||||||
#include <Autolock.h>
|
#include <Autolock.h>
|
||||||
|
|
||||||
#include "ServerApp.h"
|
#include "ServerApp.h"
|
||||||
|
#include "ServerMemoryAllocator.h"
|
||||||
|
|
||||||
|
|
||||||
typedef block_list::Iterator block_iterator;
|
typedef block_list::Iterator block_iterator;
|
||||||
@@ -364,6 +365,10 @@ ClientMemory::AreaOffset()
|
|||||||
// #pragma mark -
|
// #pragma mark -
|
||||||
|
|
||||||
|
|
||||||
|
static BLocker sLocker("ClonedAreaMemory allocator");
|
||||||
|
static BPrivate::ServerMemoryAllocator sClonedAreaMemoryAllocator;
|
||||||
|
|
||||||
|
|
||||||
ClonedAreaMemory::ClonedAreaMemory()
|
ClonedAreaMemory::ClonedAreaMemory()
|
||||||
:
|
:
|
||||||
fClonedArea(-1),
|
fClonedArea(-1),
|
||||||
@@ -375,18 +380,18 @@ ClonedAreaMemory::ClonedAreaMemory()
|
|||||||
|
|
||||||
ClonedAreaMemory::~ClonedAreaMemory()
|
ClonedAreaMemory::~ClonedAreaMemory()
|
||||||
{
|
{
|
||||||
if (fClonedArea >= 0)
|
BAutolock locker(sLocker);
|
||||||
delete_area(fClonedArea);
|
sClonedAreaMemoryAllocator.RemoveArea(fClonedArea);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
void*
|
void*
|
||||||
ClonedAreaMemory::Clone(area_id area, uint32 offset)
|
ClonedAreaMemory::Clone(area_id area, uint32 offset)
|
||||||
{
|
{
|
||||||
fClonedArea = clone_area("server_memory", (void**)&fBase, B_ANY_ADDRESS,
|
BAutolock locker(sLocker);
|
||||||
B_READ_AREA | B_WRITE_AREA, area);
|
if (sClonedAreaMemoryAllocator.AddArea(area, fClonedArea, fBase, 0, false) != B_OK)
|
||||||
if (fBase == NULL)
|
|
||||||
return NULL;
|
return NULL;
|
||||||
|
|
||||||
fOffset = offset;
|
fOffset = offset;
|
||||||
return Address();
|
return Address();
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -89,7 +89,7 @@ private:
|
|||||||
|
|
||||||
|
|
||||||
/*! Just clones an existing area. */
|
/*! Just clones an existing area. */
|
||||||
class ClonedAreaMemory : public AreaMemory{
|
class ClonedAreaMemory : public AreaMemory {
|
||||||
public:
|
public:
|
||||||
ClonedAreaMemory();
|
ClonedAreaMemory();
|
||||||
virtual ~ClonedAreaMemory();
|
virtual ~ClonedAreaMemory();
|
||||||
|
|||||||
Reference in New Issue
Block a user