Skip to content

Commit d38e790

Browse files
author
Yuma Arakawa
committed
queue: カーネルに汎用キュー構造追加
1 parent cb24d63 commit d38e790

File tree

4 files changed

+67
-1
lines changed

4 files changed

+67
-1
lines changed

kernel/Makefile

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,7 @@ CFLAGS += -Iinclude
77
.c.o:
88
gcc $(CFLAGS) -o $@ $<
99

10-
kernel.bin: sys.o cpu.o intr.o excp.o memory.o sched.o timer.o console_io.o debug.o main.o kern_task_init.o
10+
kernel.bin: sys.o cpu.o intr.o excp.o memory.o sched.o timer.o console_io.o queue.o debug.o main.o kern_task_init.o
1111
ld -o $@ $+ -Map System.map -s -T sys.ld -x
1212

1313
sys.o: sys.S
@@ -26,6 +26,8 @@ timer.o: timer.c
2626

2727
console_io.o: console_io.c
2828

29+
queue.o: queue.c
30+
2931
debug.o: debug.c
3032

3133
main.o: main.c

kernel/include/list.h

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,9 @@
1+
#ifndef _LIST_H_
2+
#define _LIST_H_
3+
4+
struct list {
5+
struct list *next;
6+
struct list *prev;
7+
};
8+
9+
#endif /* _LIST_H_ */

kernel/include/queue.h

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,11 @@
1+
#ifndef _QUEUE_H_
2+
#define _QUEUE_H_
3+
4+
#include <list.h>
5+
6+
void queue_init(struct list *head);
7+
void queue_enq(struct list *entry, struct list *head);
8+
void queue_del(struct list *entry);
9+
void queue_dump(struct list *head);
10+
11+
#endif /* _QUEUE_H_ */

kernel/queue.c

Lines changed: 44 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,44 @@
1+
#include <queue.h>
2+
#include <list.h>
3+
#include <console_io.h>
4+
5+
void queue_init(struct list *head)
6+
{
7+
head->next = head;
8+
head->prev = head;
9+
}
10+
11+
void queue_enq(struct list *entry, struct list *head)
12+
{
13+
entry->prev = head->prev;
14+
entry->next = head;
15+
head->prev->next = entry;
16+
head->prev = entry;
17+
}
18+
19+
void queue_del(struct list *entry)
20+
{
21+
entry->prev->next = entry->next;
22+
entry->next->prev = entry->prev;
23+
}
24+
25+
void queue_dump(struct list *head)
26+
{
27+
unsigned int n;
28+
struct list *entry;
29+
30+
put_str("h : p=");
31+
dump_hex((unsigned int)head->prev, 8);
32+
put_str(", n=");
33+
dump_hex((unsigned int)head->next, 8);
34+
put_str("\r\n");
35+
36+
for (entry = head->next, n = 0; entry != head; entry = entry->next, n++) {
37+
dump_hex(n, 2);
38+
put_str(": p=");
39+
dump_hex((unsigned int)entry->prev, 8);
40+
put_str(", n=");
41+
dump_hex((unsigned int)entry->next, 8);
42+
put_str("\r\n");
43+
}
44+
}

0 commit comments

Comments
 (0)