* Why have a mutex when you don't use it?
* Ensure that at least a single allocation fits into the buffer spanning over the total requested size of the pool. This makes the mixer work again instead of crash because of a failed allocation... git-svn-id: file:///srv/svn/repos/haiku/haiku/trunk@34432 a95241bf-73f2-0310-859d-f6bbb57e9c96
This commit is contained in:
@@ -296,7 +296,9 @@ rtm_create_pool(rtm_pool** _pool, size_t totalSize, const char* name)
|
|||||||
return status;
|
return status;
|
||||||
}
|
}
|
||||||
|
|
||||||
pool->max_size = (totalSize - 1 + B_PAGE_SIZE) & ~(B_PAGE_SIZE - 1);
|
// Allocate enough space for at least one allocation over \a totalSize
|
||||||
|
pool->max_size = (totalSize + sizeof(FreeChunk) - 1 + B_PAGE_SIZE)
|
||||||
|
& ~(B_PAGE_SIZE - 1);
|
||||||
|
|
||||||
area_id area = create_area(name, &pool->heap_base, B_ANY_ADDRESS,
|
area_id area = create_area(name, &pool->heap_base, B_ANY_ADDRESS,
|
||||||
pool->max_size, B_LAZY_LOCK, B_READ_AREA | B_WRITE_AREA);
|
pool->max_size, B_LAZY_LOCK, B_READ_AREA | B_WRITE_AREA);
|
||||||
@@ -331,6 +333,11 @@ rtm_create_pool(rtm_pool** _pool, size_t totalSize, const char* name)
|
|||||||
status_t
|
status_t
|
||||||
rtm_delete_pool(rtm_pool* pool)
|
rtm_delete_pool(rtm_pool* pool)
|
||||||
{
|
{
|
||||||
|
if (pool == NULL)
|
||||||
|
return B_BAD_VALUE;
|
||||||
|
|
||||||
|
mutex_lock(&pool->lock);
|
||||||
|
|
||||||
{
|
{
|
||||||
MutexLocker _(&sPoolsLock);
|
MutexLocker _(&sPoolsLock);
|
||||||
sPools.Remove(pool);
|
sPools.Remove(pool);
|
||||||
@@ -353,6 +360,8 @@ rtm_alloc(rtm_pool* pool, size_t size)
|
|||||||
if (pool->heap_base == NULL || size == 0)
|
if (pool->heap_base == NULL || size == 0)
|
||||||
return NULL;
|
return NULL;
|
||||||
|
|
||||||
|
MutexLocker _(&pool->lock);
|
||||||
|
|
||||||
// align the size requirement to a kAlignment bytes boundary
|
// align the size requirement to a kAlignment bytes boundary
|
||||||
size = (size - 1 + kAlignment) & ~(size_t)(kAlignment - 1);
|
size = (size - 1 + kAlignment) & ~(size_t)(kAlignment - 1);
|
||||||
|
|
||||||
@@ -413,6 +422,7 @@ rtm_free(void* allocated)
|
|||||||
return B_OK;
|
return B_OK;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
MutexLocker _(&pool->lock);
|
||||||
pool->Free(allocated);
|
pool->Free(allocated);
|
||||||
return B_OK;
|
return B_OK;
|
||||||
}
|
}
|
||||||
@@ -439,6 +449,8 @@ rtm_realloc(void** _buffer, size_t newSize)
|
|||||||
return B_NO_MEMORY;
|
return B_NO_MEMORY;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
MutexLocker _(&pool->lock);
|
||||||
|
|
||||||
if (newSize == 0) {
|
if (newSize == 0) {
|
||||||
TRACE("realloc(%p, %lu) -> NULL\n", oldBuffer, newSize);
|
TRACE("realloc(%p, %lu) -> NULL\n", oldBuffer, newSize);
|
||||||
pool->Free(oldBuffer);
|
pool->Free(oldBuffer);
|
||||||
|
|||||||
Reference in New Issue
Block a user