SayoriOS  0.3.3
list.c
См. документацию.
1 
9 #include "lib/list.h"
10 
11 void list_init(list_t* list){
12  list->first = nullptr;
13  list->count = 0;
14  list->mutex = false;
15 }
16 
17 void list_add(list_t* list, list_item_t* item){
18  if (item->list == nullptr){
19  mutex_get(&(list->mutex), true);
20  if (list->first){
21  item->list = list;
22  item->next = list->first;
23  item->prev = list->first->prev;
24  item->prev->next = item;
25  item->next->prev = item;
26  } else {
27  item->list = list;
28  item->next = item;
29  item->prev = item;
30  list->first = item;
31  }
32 
33  list->count++;
34  mutex_release(&(list->mutex));
35  }
36 }
37 
38 void list_remove(list_item_t* item){
39  mutex_get(&(item->list->mutex), true);
40 
41  if (item->list->first == item) {
42  item->list->first = item->next;
43  if (item->list->first == item){
44  item->list->first = nullptr;
45  }
46  }
47  item->next->prev = item->prev;
48  item->prev->next = item->next;
49  item->list->count--;
50  mutex_release(&(item->list->mutex));
51 }
Definition: list.h:16
bool mutex_get(mutex_t *mutex, bool wait)
Получить мьютекс
Definition: sync.c:19
void mutex_release(mutex_t *mutex)
Получить ближайщий свободный блок
Definition: sync.c:36