* Temporarily switched to a recursive lock for the depot.
* While this is not a really good idea for a lock with supposedly little contention, but it'll fix bug #1731. I haven't tested it yet, but will do so in a minute :-) * I will need to rework the slab anyway so that it's possible to use it as a replacement for our heap, and then I'll switch back to a benaphore again. git-svn-id: file:///srv/svn/repos/haiku/haiku/trunk@23822 a95241bf-73f2-0310-859d-f6bbb57e9c96
This commit is contained in:
@@ -1,22 +1,17 @@
|
||||
/*
|
||||
* Copyright 2007, Hugo Santos. All Rights Reserved.
|
||||
* Distributed under the terms of the MIT License.
|
||||
*
|
||||
* Authors:
|
||||
* Hugo Santos, [email protected]
|
||||
*/
|
||||
#ifndef _SLAB_DEPOT_H_
|
||||
#define _SLAB_DEPOT_H_
|
||||
|
||||
|
||||
#include <lock.h>
|
||||
#include <KernelExport.h>
|
||||
|
||||
#ifdef __cplusplus
|
||||
extern "C" {
|
||||
#endif
|
||||
|
||||
typedef struct object_depot {
|
||||
benaphore lock;
|
||||
recursive_lock lock;
|
||||
struct depot_magazine *full, *empty;
|
||||
size_t full_count, empty_count;
|
||||
struct depot_cpu_store *stores;
|
||||
@@ -25,8 +20,12 @@ typedef struct object_depot {
|
||||
} object_depot;
|
||||
|
||||
|
||||
#ifdef __cplusplus
|
||||
extern "C" {
|
||||
#endif
|
||||
|
||||
status_t object_depot_init(object_depot *depot, uint32 flags,
|
||||
void (*return_object)(object_depot *, void *));
|
||||
void (*returnObject)(object_depot *, void *));
|
||||
void object_depot_destroy(object_depot *depot);
|
||||
|
||||
void *object_depot_obtain(object_depot *depot);
|
||||
@@ -38,4 +37,4 @@ void object_depot_make_empty(object_depot *depot);
|
||||
}
|
||||
#endif
|
||||
|
||||
#endif
|
||||
#endif /* _SLAB_DEPOT_H_ */
|
||||
|
||||
@@ -1,10 +1,8 @@
|
||||
/*
|
||||
* Copyright 2008, Axel Dörfler. All Rights Reserved.
|
||||
* Copyright 2007, Hugo Santos. All Rights Reserved.
|
||||
* Distributed under the terms of the MIT License.
|
||||
*
|
||||
* Authors:
|
||||
* Hugo Santos, [email protected]
|
||||
* Distributed under the terms of the MIT License.
|
||||
*/
|
||||
|
||||
|
||||
@@ -253,6 +251,20 @@ internal_free(void *_buffer)
|
||||
}
|
||||
|
||||
|
||||
static status_t
|
||||
recursive_lock_boot_init(recursive_lock *lock, const char *name, uint32 flags)
|
||||
{
|
||||
if (flags & CACHE_DURING_BOOT) {
|
||||
lock->sem = -1;
|
||||
lock->holder = 1;
|
||||
lock->recursion = 0;
|
||||
return B_OK;
|
||||
}
|
||||
|
||||
return recursive_lock_init(lock, name);
|
||||
}
|
||||
|
||||
|
||||
static status_t
|
||||
benaphore_boot_init(benaphore *lock, const char *name, uint32 flags)
|
||||
{
|
||||
@@ -1021,7 +1033,7 @@ push_magazine(depot_magazine *magazine, void *object)
|
||||
static bool
|
||||
exchange_with_full(object_depot *depot, depot_magazine* &magazine)
|
||||
{
|
||||
BenaphoreLocker _(depot->lock);
|
||||
RecursiveLocker _(depot->lock);
|
||||
|
||||
if (depot->full == NULL)
|
||||
return false;
|
||||
@@ -1038,7 +1050,7 @@ exchange_with_full(object_depot *depot, depot_magazine* &magazine)
|
||||
static bool
|
||||
exchange_with_empty(object_depot *depot, depot_magazine* &magazine)
|
||||
{
|
||||
BenaphoreLocker _(depot->lock);
|
||||
RecursiveLocker _(depot->lock);
|
||||
|
||||
if (depot->empty == NULL) {
|
||||
depot->empty = alloc_magazine();
|
||||
@@ -1097,14 +1109,14 @@ object_depot_init(object_depot *depot, uint32 flags,
|
||||
depot->empty = NULL;
|
||||
depot->full_count = depot->empty_count = 0;
|
||||
|
||||
status_t status = benaphore_boot_init(&depot->lock, "depot", flags);
|
||||
status_t status = recursive_lock_boot_init(&depot->lock, "depot", flags);
|
||||
if (status < B_OK)
|
||||
return status;
|
||||
|
||||
depot->stores = (depot_cpu_store *)internal_alloc(sizeof(depot_cpu_store)
|
||||
* smp_get_num_cpus(), flags);
|
||||
if (depot->stores == NULL) {
|
||||
benaphore_destroy(&depot->lock);
|
||||
recursive_lock_destroy(&depot->lock);
|
||||
return B_NO_MEMORY;
|
||||
}
|
||||
|
||||
@@ -1122,7 +1134,7 @@ object_depot_init(object_depot *depot, uint32 flags,
|
||||
status_t
|
||||
object_depot_init_locks(object_depot *depot)
|
||||
{
|
||||
status_t status = benaphore_init(&depot->lock, "depot");
|
||||
status_t status = recursive_lock_init(&depot->lock, "depot");
|
||||
if (status < B_OK)
|
||||
return status;
|
||||
|
||||
@@ -1147,7 +1159,7 @@ object_depot_destroy(object_depot *depot)
|
||||
|
||||
internal_free(depot->stores);
|
||||
|
||||
benaphore_destroy(&depot->lock);
|
||||
recursive_lock_destroy(&depot->lock);
|
||||
}
|
||||
|
||||
|
||||
@@ -1233,7 +1245,7 @@ object_depot_make_empty(object_depot *depot)
|
||||
depot->stores[i].loaded = depot->stores[i].previous = NULL;
|
||||
}
|
||||
|
||||
BenaphoreLocker _(depot->lock);
|
||||
RecursiveLocker _(depot->lock);
|
||||
|
||||
while (depot->full)
|
||||
empty_magazine(depot, _pop(depot->full));
|
||||
|
||||
Reference in New Issue
Block a user