list: change locking discipline
Signed-off-by: Michael Shaw <m@michaelsshaw.com>
This commit is contained in:
parent
2cf76fd225
commit
071a5651e0
11 changed files with 61 additions and 15 deletions
24
lib/list.c
24
lib/list.c
|
|
@ -15,9 +15,7 @@ void list_create(list_t *list)
|
|||
|
||||
void list_destroy(list_t *list)
|
||||
{
|
||||
spinlock_acquire(&list->lock);
|
||||
list_item_t *item = list->head;
|
||||
|
||||
while (item) {
|
||||
list_item_t *next = item->next;
|
||||
slab_free(list_cache, item);
|
||||
|
|
@ -25,17 +23,14 @@ void list_destroy(list_t *list)
|
|||
}
|
||||
list->head = NULL;
|
||||
list->tail = NULL;
|
||||
spinlock_release(&list->lock);
|
||||
}
|
||||
|
||||
list_item_t *list_insert(list_t *list, void *item)
|
||||
{
|
||||
spinlock_acquire(&list->lock);
|
||||
list_item_t *ret = slab_alloc(list_cache);
|
||||
if (!ret) {
|
||||
spinlock_release(&list->lock);
|
||||
if (!ret)
|
||||
return NULL;
|
||||
}
|
||||
|
||||
ret->ptr = item;
|
||||
ret->list = list;
|
||||
ret->next = NULL;
|
||||
|
|
@ -50,8 +45,6 @@ list_item_t *list_insert(list_t *list, void *item)
|
|||
}
|
||||
|
||||
list->tail = ret;
|
||||
spinlock_release(&list->lock);
|
||||
|
||||
return ret;
|
||||
}
|
||||
|
||||
|
|
@ -59,7 +52,6 @@ void list_remove(list_item_t *item)
|
|||
{
|
||||
list_t *list = item->list;
|
||||
|
||||
spinlock_acquire(&list->lock);
|
||||
if (item == list->head)
|
||||
list->head = item->next;
|
||||
if (item == list->tail)
|
||||
|
|
@ -67,14 +59,22 @@ void list_remove(list_item_t *item)
|
|||
|
||||
if (item->next)
|
||||
item->next->prev = item->prev;
|
||||
|
||||
if (item->prev)
|
||||
item->prev->next = item->next;
|
||||
spinlock_release(&list->lock);
|
||||
|
||||
slab_free(list_cache, item);
|
||||
}
|
||||
|
||||
void list_lock(list_t *list)
|
||||
{
|
||||
spinlock_acquire(&list->lock);
|
||||
}
|
||||
|
||||
void list_unlock(list_t *list)
|
||||
{
|
||||
spinlock_release(&list->lock);
|
||||
}
|
||||
|
||||
void list_init()
|
||||
{
|
||||
list_cache = slab_create("list_cache", sizeof(list_item_t), 64 * KB, 0x8);
|
||||
|
|
|
|||
Loading…
Reference in a new issue