Fixed pretty much broken AreaPool - I am not sure this class is that a good idea, anyway.
area_for() is not the cheapest call; the user better knows the area and deletes it directly. Minor cleanup. git-svn-id: file:///srv/svn/repos/haiku/haiku/trunk@13257 a95241bf-73f2-0310-859d-f6bbb57e9c96
This commit is contained in:
+32
-32
@@ -1,13 +1,13 @@
|
|||||||
/*
|
/*
|
||||||
* Copyright 2001-2005, Haiku, Inc. All rights reserved.
|
* Copyright 2001-2005, Haiku, Inc. All rights reserved.
|
||||||
* Distributed under the terms of the MIT License.
|
* Distributed under the terms of the MIT License.
|
||||||
|
*
|
||||||
* Authors: John Walker <[email protected]>
|
* Authors:
|
||||||
* DarkWyrm <[email protected]>
|
* John Walker <[email protected]>
|
||||||
* Stephan Aßmus <[email protected]>
|
* DarkWyrm <[email protected]>
|
||||||
|
* Stephan Aßmus <[email protected]>
|
||||||
*
|
*
|
||||||
* BGET pool allocator
|
* BGET pool allocator
|
||||||
*
|
|
||||||
*/
|
*/
|
||||||
|
|
||||||
/*
|
/*
|
||||||
@@ -65,6 +65,7 @@ MemPool::MemPool()
|
|||||||
fFreeList.ql = (qlinks){ &fFreeList, &fFreeList };
|
fFreeList.ql = (qlinks){ &fFreeList, &fFreeList };
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
MemPool::~MemPool()
|
MemPool::~MemPool()
|
||||||
{
|
{
|
||||||
}
|
}
|
||||||
@@ -572,7 +573,6 @@ MemPool::ExtendedStats(ssize_t *pool_incr, long *npool, long *npget, long *nprel
|
|||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
// Dump the data in a buffer. This is called with the user data pointer,
|
// Dump the data in a buffer. This is called with the user data pointer,
|
||||||
// and backs up to the buffer header. It will dump either a free block
|
// and backs up to the buffer header. It will dump either a free block
|
||||||
// or an allocated one.
|
// or an allocated one.
|
||||||
@@ -663,8 +663,8 @@ MemPool::PoolDump(void *buf, bool dumpalloc, bool dumpfree)
|
|||||||
}
|
}
|
||||||
else
|
else
|
||||||
{
|
{
|
||||||
char *lerr = "";
|
char *lerr = "";
|
||||||
|
|
||||||
assert(bs > 0);
|
assert(bs > 0);
|
||||||
if ((b->ql.blink->ql.flink != b) || (b->ql.flink->ql.blink != b))
|
if ((b->ql.blink->ql.flink != b) || (b->ql.flink->ql.blink != b))
|
||||||
{
|
{
|
||||||
@@ -740,69 +740,69 @@ MemPool::Validate(void *buf)
|
|||||||
return 1;
|
return 1;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
int*
|
int*
|
||||||
MemPool::CompactMem(ssize_t sizereq, int sequence)
|
MemPool::CompactMem(ssize_t sizereq, int sequence)
|
||||||
{
|
{
|
||||||
return NULL;
|
return NULL;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
void*
|
void*
|
||||||
MemPool::AcquireMem(ssize_t size)
|
MemPool::AcquireMem(ssize_t size)
|
||||||
{
|
{
|
||||||
return malloc(size);
|
return malloc(size);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
void
|
void
|
||||||
MemPool::ReleaseMem(void *buffer)
|
MemPool::ReleaseMem(void *buffer)
|
||||||
{
|
{
|
||||||
free(buffer);
|
free(buffer);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
// #pragma mark -
|
||||||
|
|
||||||
|
|
||||||
AreaPool::AreaPool()
|
AreaPool::AreaPool()
|
||||||
{
|
{
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
AreaPool::~AreaPool()
|
AreaPool::~AreaPool()
|
||||||
{
|
{
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
void*
|
void*
|
||||||
AreaPool::AcquireMem(ssize_t size)
|
AreaPool::AcquireMem(ssize_t size)
|
||||||
{
|
{
|
||||||
long areasize=0;
|
area_id area;
|
||||||
area_id a;
|
void* address;
|
||||||
int *parea;
|
|
||||||
|
// make size a multiple of B_PAGE_SIZE
|
||||||
if(size<B_PAGE_SIZE)
|
size = (size + B_PAGE_SIZE - 1) & ~(B_PAGE_SIZE - 1);
|
||||||
areasize=B_PAGE_SIZE;
|
|
||||||
else
|
area = create_area("AreaPool_area", &address, B_ANY_ADDRESS, size,
|
||||||
{
|
B_NO_LOCK, B_READ_AREA | B_WRITE_AREA);
|
||||||
if((size % B_PAGE_SIZE)!=0)
|
|
||||||
areasize=((long)(size/B_PAGE_SIZE)+1)*B_PAGE_SIZE;
|
if (area < B_OK) {
|
||||||
else
|
|
||||||
areasize=size;
|
|
||||||
}
|
|
||||||
|
|
||||||
a=create_area("AreaPool_area",(void**)&parea,B_ANY_ADDRESS,areasize,
|
|
||||||
B_NO_LOCK, B_READ_AREA | B_WRITE_AREA);
|
|
||||||
|
|
||||||
if(a==B_BAD_VALUE || a==B_NO_MEMORY || a==B_ERROR)
|
|
||||||
{
|
|
||||||
printf("ERROR: AreaPool couldn't allocate area!!\n");
|
printf("ERROR: AreaPool couldn't allocate area!!\n");
|
||||||
return NULL;
|
return NULL;
|
||||||
}
|
}
|
||||||
|
|
||||||
return parea;
|
return address;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
void
|
void
|
||||||
AreaPool::ReleaseMem(void *buffer)
|
AreaPool::ReleaseMem(void *buffer)
|
||||||
{
|
{
|
||||||
area_id trash=area_for(buffer);
|
area_id trash = area_for(buffer);
|
||||||
|
if (trash < B_ERROR)
|
||||||
if(trash==B_ERROR)
|
|
||||||
return;
|
return;
|
||||||
|
|
||||||
delete_area(trash);
|
delete_area(trash);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
Reference in New Issue
Block a user