* Quick&dirty fix of a race condition that caused an endless loop in

object_cache_alloc(): the ObjectCache::total_objects count was increased in
  ObjectCache::InitSlab(), but the slab was really only added at a later point
  between the cache could be unlocked.
* If a second object_cache_reserve_internal() managed to be called while the
  lock was unlocked, it would see that there has to be space available, and
  will then return -- however, since the other thread could not yet place the
  slab into the cache, object_cache_alloc() cannot find it.


git-svn-id: file:///srv/svn/repos/haiku/haiku/trunk@35702 a95241bf-73f2-0310-859d-f6bbb57e9c96
This commit is contained in:
Axel Dörfler
2010-03-01 16:35:17 +00:00
parent 2056103694
commit 1c164de7d2
2 changed files with 4 additions and 3 deletions
-3
View File
@@ -166,9 +166,6 @@ ObjectCache::InitSlab(slab* slab, void* pages, size_t byteCount, uint32 flags)
data += object_size;
}
usage += slab_size;
total_objects += slab->size;
return slab;
}
+4
View File
@@ -232,6 +232,7 @@ dump_cache_info(int argc, char* argv[])
kprintf("lock: %p\n", &cache->lock);
kprintf("object_size: %lu\n", cache->object_size);
kprintf("cache_color_cycle: %lu\n", cache->cache_color_cycle);
kprintf("total_objects: %lu\n", cache->total_objects);
kprintf("used_count: %lu\n", cache->used_count);
kprintf("empty_count: %lu\n", cache->empty_count);
kprintf("pressure: %lu\n", cache->pressure);
@@ -362,6 +363,9 @@ object_cache_reserve_internal(ObjectCache* cache, size_t objectCount,
return B_NO_MEMORY;
}
cache->usage += cache->slab_size;
cache->total_objects += newSlab->size;
cache->empty.Add(newSlab);
cache->empty_count++;
}