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:
Augustin Cavalier
2025-11-18 20:10:05 -05:00
parent 2661f371fb
commit fe8f88cff4
2 changed files with 11 additions and 6 deletions
+10 -5
View File
@@ -26,6 +26,7 @@
#include <Autolock.h>
#include "ServerApp.h"
#include "ServerMemoryAllocator.h"
typedef block_list::Iterator block_iterator;
@@ -364,6 +365,10 @@ ClientMemory::AreaOffset()
// #pragma mark -
static BLocker sLocker("ClonedAreaMemory allocator");
static BPrivate::ServerMemoryAllocator sClonedAreaMemoryAllocator;
ClonedAreaMemory::ClonedAreaMemory()
:
fClonedArea(-1),
@@ -375,18 +380,18 @@ ClonedAreaMemory::ClonedAreaMemory()
ClonedAreaMemory::~ClonedAreaMemory()
{
if (fClonedArea >= 0)
delete_area(fClonedArea);
BAutolock locker(sLocker);
sClonedAreaMemoryAllocator.RemoveArea(fClonedArea);
}
void*
ClonedAreaMemory::Clone(area_id area, uint32 offset)
{
fClonedArea = clone_area("server_memory", (void**)&fBase, B_ANY_ADDRESS,
B_READ_AREA | B_WRITE_AREA, area);
if (fBase == NULL)
BAutolock locker(sLocker);
if (sClonedAreaMemoryAllocator.AddArea(area, fClonedArea, fBase, 0, false) != B_OK)
return NULL;
fOffset = offset;
return Address();
}
+1 -1
View File
@@ -89,7 +89,7 @@ private:
/*! Just clones an existing area. */
class ClonedAreaMemory : public AreaMemory{
class ClonedAreaMemory : public AreaMemory {
public:
ClonedAreaMemory();
virtual ~ClonedAreaMemory();