source: rtems/cpukit/libdrvmgr/drvmgr_list.c @ 30594a9

4.115
Last change on this file since 30594a9 was e7fade3, checked in by Daniel Hellstrom <daniel@…>, on 11/28/11 at 08:52:03

DRVMGR: added driver manager to cpukit/libdrvmgr

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