source: rtems/cpukit/libdrvmgr/drvmgr_list.c @ bef5e23e

4.115
Last change on this file since bef5e23e was 0decc806, checked in by Daniel Hellstrom <daniel@…>, on 04/09/15 at 14:09:13

DRVMGR: updated license to rtems.org

  • Property mode set to 100644
File size: 1.4 KB
Line 
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
15void drvmgr_list_init(struct drvmgr_list *list, int offset)
16{
17        list->head = list->tail = NULL;
18        list->ofs = offset;
19}
20
21void drvmgr_list_empty(struct drvmgr_list *list)
22{
23        list->head = list->tail = NULL;
24}
25
26void 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
34void 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
44void 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
51void 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}
Note: See TracBrowser for help on using the repository browser.