1 | /* Driver Manager List Interface Implementation. |
---|
2 | * |
---|
3 | * COPYRIGHT (c) 2009 Cobham Gaisler AB. |
---|
4 | * |
---|
5 | * The license and distribution terms for this file may be |
---|
6 | * found in the file LICENSE in this distribution or at |
---|
7 | * http://www.rtems.org/license/LICENSE. |
---|
8 | */ |
---|
9 | |
---|
10 | #include <stdlib.h> |
---|
11 | #include <drvmgr/drvmgr_list.h> |
---|
12 | |
---|
13 | /* LIST interface */ |
---|
14 | |
---|
15 | void drvmgr_list_init(struct drvmgr_list *list, int offset) |
---|
16 | { |
---|
17 | list->head = list->tail = NULL; |
---|
18 | list->ofs = offset; |
---|
19 | } |
---|
20 | |
---|
21 | void drvmgr_list_empty(struct drvmgr_list *list) |
---|
22 | { |
---|
23 | list->head = list->tail = NULL; |
---|
24 | } |
---|
25 | |
---|
26 | void drvmgr_list_add_head(struct drvmgr_list *list, void *entry) |
---|
27 | { |
---|
28 | LIST_FIELD(list, entry) = list->head; |
---|
29 | if (list->head == NULL) |
---|
30 | list->tail = entry; |
---|
31 | list->head = entry; |
---|
32 | } |
---|
33 | |
---|
34 | void drvmgr_list_add_tail(struct drvmgr_list *list, void *entry) |
---|
35 | { |
---|
36 | if (list->tail == NULL) |
---|
37 | list->head = entry; |
---|
38 | else |
---|
39 | LIST_FIELD(list, list->tail) = entry; |
---|
40 | LIST_FIELD(list, entry) = NULL; |
---|
41 | list->tail = entry; |
---|
42 | } |
---|
43 | |
---|
44 | void drvmgr_list_remove_head(struct drvmgr_list *list) |
---|
45 | { |
---|
46 | list->head = LIST_FIELD(list, list->head); |
---|
47 | if (list->head == NULL) |
---|
48 | list->tail = NULL; |
---|
49 | } |
---|
50 | |
---|
51 | void drvmgr_list_remove(struct drvmgr_list *list, void *entry) |
---|
52 | { |
---|
53 | void **prevptr = &list->head; |
---|
54 | void *curr, *prev; |
---|
55 | |
---|
56 | prev = NULL; |
---|
57 | curr = list->head; |
---|
58 | while (curr != entry) { |
---|
59 | prev = curr; |
---|
60 | prevptr = &LIST_FIELD(list, curr); |
---|
61 | curr = LIST_FIELD(list, curr); |
---|
62 | } |
---|
63 | *prevptr = LIST_FIELD(list, entry); |
---|
64 | if (list->tail == entry) |
---|
65 | list->tail = prev; |
---|
66 | } |
---|