Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with HTTPS or Subversion.

Download ZIP
Newer
Older
100644 113 lines (95 sloc) 3.326 kb
0d11ec1 gdev: changed the interfaces of time and list management
Shinpei Kato authored
1 /*
fdb72d9 @shinpei0208 fixed license text everywhere
authored
2 * Copyright (C) Shinpei Kato
fe052f5 gdev: refactored code and cleaned up files
Shinpei Kato authored
3 *
4 * University of California, Santa Cruz
5 * Systems Research Lab.
6 *
7 * All Rights Reserved.
8 *
9 * Permission is hereby granted, free of charge, to any person obtaining a
10 * copy of this software and associated documentation files (the "Software"),
11 * to deal in the Software without restriction, including without limitation
12 * the rights to use, copy, modify, merge, publish, distribute, sublicense,
13 * and/or sell copies of the Software, and to permit persons to whom the
14 * Software is furnished to do so, subject to the following conditions:
15 *
16 * The above copyright notice and this permission notice (including the next
17 * paragraph) shall be included in all copies or substantial portions of the
18 * Software.
19 *
20 * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
21 * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
22 * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL
943bcbe @shinpei0208 fixed license text everywhere
authored
23 * THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR
fe052f5 gdev: refactored code and cleaned up files
Shinpei Kato authored
24 * OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE,
25 * ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR
26 * OTHER DEALINGS IN THE SOFTWARE.
27 */
0d11ec1 gdev: changed the interfaces of time and list management
Shinpei Kato authored
28
29 #ifndef __GDEV_LIST_H__
30 #define __GDEV_LIST_H__
31
32 #ifndef NULL
33 #define NULL 0
34 #endif
35
36 /* a list structure: we could use Linux's list_head, but it's not available
37 in user-space - hence use our own list structure. */
61b3736 refactored code
Shinpei Kato authored
38 struct gdev_list {
0d11ec1 gdev: changed the interfaces of time and list management
Shinpei Kato authored
39 struct gdev_list *next;
40 struct gdev_list *prev;
41 void *container;
61b3736 refactored code
Shinpei Kato authored
42 };
0d11ec1 gdev: changed the interfaces of time and list management
Shinpei Kato authored
43
61b3736 refactored code
Shinpei Kato authored
44 static inline void gdev_list_init(struct gdev_list *entry, void *container)
0d11ec1 gdev: changed the interfaces of time and list management
Shinpei Kato authored
45 {
d964e7e gdev: implemented the Credit scheduling algorithm for virtual devices
Shinpei Kato authored
46 entry->next = entry->prev = entry; /* used to be "= NULL" */
0d11ec1 gdev: changed the interfaces of time and list management
Shinpei Kato authored
47 entry->container = container;
48 }
49
e52b661 gdev: added a priority-based scheduler
Shinpei Kato authored
50 static inline void gdev_list_add_next(struct gdev_list *entry, struct gdev_list *pos)
51 {
52 struct gdev_list *next = pos->next;
53
54 entry->next = next;
0f65017 gdev: fixed the scheduler
Shinpei Kato authored
55 next->prev = entry;
e52b661 gdev: added a priority-based scheduler
Shinpei Kato authored
56 entry->prev = pos;
57 pos->next = entry;
58 }
59
60 static inline void gdev_list_add_prev(struct gdev_list *entry, struct gdev_list *pos)
61 {
62 struct gdev_list *prev = pos->prev;
63
64 entry->prev = prev;
0f65017 gdev: fixed the scheduler
Shinpei Kato authored
65 prev->next = entry;
e52b661 gdev: added a priority-based scheduler
Shinpei Kato authored
66 entry->next = pos;
67 pos->prev = entry;
68 }
69
d964e7e gdev: implemented the Credit scheduling algorithm for virtual devices
Shinpei Kato authored
70 static inline void gdev_list_add(struct gdev_list *entry, struct gdev_list *head)
71 {
72 return gdev_list_add_next(entry, head);
73 }
74
75 static inline void gdev_list_add_tail(struct gdev_list *entry, struct gdev_list *head)
76 {
77 return gdev_list_add_prev(entry, head);
78 }
79
61b3736 refactored code
Shinpei Kato authored
80 static inline void gdev_list_del(struct gdev_list *entry)
0d11ec1 gdev: changed the interfaces of time and list management
Shinpei Kato authored
81 {
82 struct gdev_list *next = entry->next;
83 struct gdev_list *prev = entry->prev;
a9bb2ef gdev: fixed a __gdev_list_del function
Shinpei Kato authored
84
85 /* if prev is null, @entry points to the head, hence something wrong. */
0f65017 gdev: fixed the scheduler
Shinpei Kato authored
86 prev->next = next;
87 next->prev = prev;
88 entry->next = entry->prev = entry;
0d11ec1 gdev: changed the interfaces of time and list management
Shinpei Kato authored
89 }
90
24896dd pscnv: fixed missing pscnv_mem_free() in pscnv_mm.c
Shinpei Kato authored
91 static inline int gdev_list_empty(struct gdev_list *entry)
92 {
0f65017 gdev: fixed the scheduler
Shinpei Kato authored
93 return (entry->next == entry->prev) && (entry->next == entry);
24896dd pscnv: fixed missing pscnv_mem_free() in pscnv_mm.c
Shinpei Kato authored
94 }
95
61b3736 refactored code
Shinpei Kato authored
96 static inline struct gdev_list *gdev_list_head(struct gdev_list *head)
0d11ec1 gdev: changed the interfaces of time and list management
Shinpei Kato authored
97 {
d964e7e gdev: implemented the Credit scheduling algorithm for virtual devices
Shinpei Kato authored
98 /* head->next is the actual head of the list. */
0f65017 gdev: fixed the scheduler
Shinpei Kato authored
99 return (head && !gdev_list_empty(head)) ? head->next : NULL;
0d11ec1 gdev: changed the interfaces of time and list management
Shinpei Kato authored
100 }
101
61b3736 refactored code
Shinpei Kato authored
102 static inline void *gdev_list_container(struct gdev_list *entry)
0d11ec1 gdev: changed the interfaces of time and list management
Shinpei Kato authored
103 {
a9bb2ef gdev: fixed a __gdev_list_del function
Shinpei Kato authored
104 return entry ? entry->container : NULL;
0d11ec1 gdev: changed the interfaces of time and list management
Shinpei Kato authored
105 }
106
e52b661 gdev: added a priority-based scheduler
Shinpei Kato authored
107 #define gdev_list_for_each(p, list, entry_name) \
61b3736 refactored code
Shinpei Kato authored
108 for (p = gdev_list_container(gdev_list_head(list)); \
38a1e94 gdev: fixed a regression bug regarding memory heap management
Shinpei Kato authored
109 p != NULL; \
e52b661 gdev: added a priority-based scheduler
Shinpei Kato authored
110 p = gdev_list_container((p)->entry_name.next))
24896dd pscnv: fixed missing pscnv_mem_free() in pscnv_mm.c
Shinpei Kato authored
111
0d11ec1 gdev: changed the interfaces of time and list management
Shinpei Kato authored
112 #endif
Something went wrong with that request. Please try again.