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