[haiku-commits] r34432 - haiku/trunk/src/kits/media

  • From: axeld@xxxxxxxxxxxxxxxx
  • To: haiku-commits@xxxxxxxxxxxxx
  • Date: Tue, 1 Dec 2009 23:23:48 +0100 (CET)

Author: axeld
Date: 2009-12-01 23:23:48 +0100 (Tue, 01 Dec 2009)
New Revision: 34432
Changeset: http://dev.haiku-os.org/changeset/34432/haiku

Modified:
   haiku/trunk/src/kits/media/RealtimeAlloc.cpp
Log:
* 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...


Modified: haiku/trunk/src/kits/media/RealtimeAlloc.cpp
===================================================================
--- haiku/trunk/src/kits/media/RealtimeAlloc.cpp        2009-12-01 22:06:31 UTC 
(rev 34431)
+++ haiku/trunk/src/kits/media/RealtimeAlloc.cpp        2009-12-01 22:23:48 UTC 
(rev 34432)
@@ -296,7 +296,9 @@
                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,
                pool->max_size, B_LAZY_LOCK, B_READ_AREA | B_WRITE_AREA);
@@ -331,6 +333,11 @@
 status_t
 rtm_delete_pool(rtm_pool* pool)
 {
+       if (pool == NULL)
+               return B_BAD_VALUE;
+
+       mutex_lock(&pool->lock);
+
        {
                MutexLocker _(&sPoolsLock);
                sPools.Remove(pool);
@@ -353,6 +360,8 @@
        if (pool->heap_base == NULL || size == 0)
                return NULL;
 
+       MutexLocker _(&pool->lock);
+
        // align the size requirement to a kAlignment bytes boundary
        size = (size - 1 + kAlignment) & ~(size_t)(kAlignment - 1);
 
@@ -413,6 +422,7 @@
                return B_OK;
        }
 
+       MutexLocker _(&pool->lock);
        pool->Free(allocated);
        return B_OK;
 }
@@ -439,6 +449,8 @@
                return B_NO_MEMORY;
        }
 
+       MutexLocker _(&pool->lock);
+
        if (newSize == 0) {
                TRACE("realloc(%p, %lu) -> NULL\n", oldBuffer, newSize);
                pool->Free(oldBuffer);


Other related posts:

  • » [haiku-commits] r34432 - haiku/trunk/src/kits/media - axeld