|
@@ -0,0 +1,56 @@
|
|
1
|
+/*
|
|
2
|
+ * Copyright (C) 2006 Michael Brown <mbrown@fensystems.co.uk>.
|
|
3
|
+ *
|
|
4
|
+ * This program is free software; you can redistribute it and/or
|
|
5
|
+ * modify it under the terms of the GNU General Public License as
|
|
6
|
+ * published by the Free Software Foundation; either version 2 of the
|
|
7
|
+ * License, or any later version.
|
|
8
|
+ *
|
|
9
|
+ * This program is distributed in the hope that it will be useful, but
|
|
10
|
+ * WITHOUT ANY WARRANTY; without even the implied warranty of
|
|
11
|
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
|
|
12
|
+ * General Public License for more details.
|
|
13
|
+ *
|
|
14
|
+ * You should have received a copy of the GNU General Public License
|
|
15
|
+ * along with this program; if not, write to the Free Software
|
|
16
|
+ * Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
|
|
17
|
+ */
|
|
18
|
+
|
|
19
|
+#include <gpxe/list.h>
|
|
20
|
+#include <gpxe/process.h>
|
|
21
|
+
|
|
22
|
+/** @file
|
|
23
|
+ *
|
|
24
|
+ * Processes
|
|
25
|
+ *
|
|
26
|
+ * We implement a trivial form of cooperative multitasking, in which
|
|
27
|
+ * all processes share a single stack and address space.
|
|
28
|
+ */
|
|
29
|
+
|
|
30
|
+/** Process run queue */
|
|
31
|
+static LIST_HEAD ( run_queue );
|
|
32
|
+
|
|
33
|
+/**
|
|
34
|
+ * Add process to run queue
|
|
35
|
+ *
|
|
36
|
+ * @v process Process
|
|
37
|
+ */
|
|
38
|
+void schedule ( struct process *process ) {
|
|
39
|
+ list_add_tail ( &process->list, &run_queue );
|
|
40
|
+}
|
|
41
|
+
|
|
42
|
+/**
|
|
43
|
+ * Single-step a single process
|
|
44
|
+ *
|
|
45
|
+ * This removes the first process from the run queue and executes a
|
|
46
|
+ * single step of that process.
|
|
47
|
+ */
|
|
48
|
+void step ( void ) {
|
|
49
|
+ struct process *process;
|
|
50
|
+
|
|
51
|
+ list_for_each_entry ( process, &run_queue, list ) {
|
|
52
|
+ list_del ( &process->list );
|
|
53
|
+ process->step ( process );
|
|
54
|
+ break;
|
|
55
|
+ }
|
|
56
|
+}
|