1 /*
2 * Copyright 2011 Tom Stellard <[email protected]>
3 * SPDX-License-Identifier: MIT
4 */
5
6 #include "radeon_list.h"
7
8 #include <stdlib.h>
9 #include <stdio.h>
10
11 #include "memory_pool.h"
12
rc_list(struct memory_pool * pool,void * item)13 struct rc_list * rc_list(struct memory_pool * pool, void * item)
14 {
15 struct rc_list * new = memory_pool_malloc(pool, sizeof(struct rc_list));
16 new->Item = item;
17 new->Next = NULL;
18 new->Prev = NULL;
19
20 return new;
21 }
22
rc_list_add(struct rc_list ** list,struct rc_list * new_value)23 void rc_list_add(struct rc_list ** list, struct rc_list * new_value)
24 {
25 struct rc_list * temp;
26
27 if (*list == NULL) {
28 *list = new_value;
29 return;
30 }
31
32 for (temp = *list; temp->Next; temp = temp->Next);
33
34 temp->Next = new_value;
35 new_value->Prev = temp;
36 }
37
rc_list_remove(struct rc_list ** list,struct rc_list * rm_value)38 void rc_list_remove(struct rc_list ** list, struct rc_list * rm_value)
39 {
40 if (*list == rm_value) {
41 *list = rm_value->Next;
42 return;
43 }
44
45 rm_value->Prev->Next = rm_value->Next;
46 if (rm_value->Next) {
47 rm_value->Next->Prev = rm_value->Prev;
48 }
49 }
50
rc_list_count(struct rc_list * list)51 unsigned int rc_list_count(struct rc_list * list)
52 {
53 unsigned int count = 0;
54 while (list) {
55 count++;
56 list = list->Next;
57 }
58 return count;
59 }
60
rc_list_print(struct rc_list * list)61 void rc_list_print(struct rc_list * list)
62 {
63 while(list) {
64 fprintf(stderr, "%p->", list->Item);
65 list = list->Next;
66 }
67 fprintf(stderr, "\n");
68 }
69