-
Notifications
You must be signed in to change notification settings - Fork 0
/
list.c
75 lines (63 loc) · 1.61 KB
/
list.c
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
/*-----------------------------------------------------------------------------
*
* Ring list
* (c) maisvendoo, 02.08.2013
*
*---------------------------------------------------------------------------*/
#include "list.h"
/*-----------------------------------------------------------------------------
*
*---------------------------------------------------------------------------*/
void list_init(list_t* list)
{
list->first = NULL;
list->count = 0;
list->mutex = false;
}
/*-----------------------------------------------------------------------------
*
*---------------------------------------------------------------------------*/
void list_add(list_t* list, list_item_t* item)
{
if (item->list == NULL)
{
/*mutex_get(&(list->mutex), true);*/
if (list->first)
{
item->list = list;
item->next = list->first;
item->prev = list->first->prev;
item->prev->next = item;
item->next->prev = item;
}
else
{
item->list = list;
item->next = item;
item->prev = item;
list->first = item;
}
list->count++;
/*mutex_release(&(list->mutex));*/
}
}
/*-----------------------------------------------------------------------------
*
*---------------------------------------------------------------------------*/
void list_remove(list_item_t* item)
{
/*mutex_get(&(item->list->mutex), true);*/
if (item->list->first == item)
{
item->list->first = item->next;
if (item->list->first == item)
{
item->list->first = NULL;
}
}
item->next->prev = item->prev;
item->prev->next = item->next;
item->list->count--;
/*item->list = NULL;*/
/*mutex_release(&(item->list->mutex));*/
}