Author: bonefish Date: 2010-01-20 11:56:34 +0100 (Wed, 20 Jan 2010) New Revision: 35198 Changeset: http://dev.haiku-os.org/changeset/35198/haiku Modified: haiku/trunk/src/system/kernel/slab/Slab.cpp Log: Shuffled functions a bit, so that they are in a reasonable order. Modified: haiku/trunk/src/system/kernel/slab/Slab.cpp =================================================================== --- haiku/trunk/src/system/kernel/slab/Slab.cpp 2010-01-20 10:28:18 UTC (rev 35197) +++ haiku/trunk/src/system/kernel/slab/Slab.cpp 2010-01-20 10:56:34 UTC (rev 35198) @@ -60,9 +60,6 @@ static uint8* sInitialLimit; static uint8* sInitialPointer; -static status_t object_cache_reserve_internal(ObjectCache* cache, - size_t object_count, uint32 flags, bool unlockWhileAllocating); - static mutex sResizeRequestsLock = MUTEX_INITIALIZER("object cache resize requests"); static ResizeRequestQueue sResizeRequests; @@ -299,7 +296,47 @@ } +// #pragma mark - + + static void +increase_object_reserve(ObjectCache* cache) +{ + if (cache->resize_request->pending) + return; + + cache->resize_request->pending = true; + + MutexLocker locker(sResizeRequestsLock); + sResizeRequests.Add(cache->resize_request); + sResizeRequestsCondition.NotifyAll(); +} + + +static status_t +object_cache_reserve_internal(ObjectCache* cache, size_t objectCount, + uint32 flags, bool unlockWhileAllocating) +{ + size_t numBytes = objectCount * cache->object_size; + size_t slabCount = ((numBytes - 1) / cache->slab_size) + 1; + // TODO: This also counts the unusable space of each slab, which can + // sum up. + + while (slabCount > 0) { + slab* newSlab = cache->CreateSlab(flags, unlockWhileAllocating); + if (newSlab == NULL) + return B_NO_MEMORY; + + cache->empty.Add(newSlab); + cache->empty_count++; + slabCount--; + } + + return B_OK; +} + + +static void object_cache_low_memory(void* _self, uint32 resources, int32 level) { if (level == B_NO_LOW_RESOURCE) @@ -414,20 +451,9 @@ } -static void -increase_object_reserve(ObjectCache* cache) -{ - if (cache->resize_request->pending) - return; +// #pragma mark - public API - cache->resize_request->pending = true; - MutexLocker locker(sResizeRequestsLock); - sResizeRequests.Add(cache->resize_request); - sResizeRequestsCondition.NotifyAll(); -} - - object_cache* create_object_cache(const char* name, size_t object_size, size_t alignment, void* cookie, object_cache_constructor constructor, @@ -601,29 +627,6 @@ } -static status_t -object_cache_reserve_internal(ObjectCache* cache, size_t objectCount, - uint32 flags, bool unlockWhileAllocating) -{ - size_t numBytes = objectCount* cache->object_size; - size_t slabCount = ((numBytes - 1) / cache->slab_size) + 1; - // TODO: This also counts the unusable space of each slab, which can - // sum up. - - while (slabCount > 0) { - slab* newSlab = cache->CreateSlab(flags, unlockWhileAllocating); - if (newSlab == NULL) - return B_NO_MEMORY; - - cache->empty.Add(newSlab); - cache->empty_count++; - slabCount--; - } - - return B_OK; -} - - status_t object_cache_reserve(object_cache* cache, size_t objectCount, uint32 flags) {