summaryrefslogtreecommitdiffstats
path: root/src
diff options
context:
space:
mode:
authorMichael Brown2006-04-29 18:42:09 +0200
committerMichael Brown2006-04-29 18:42:09 +0200
commit23c494d14efafdd1dd06cec53665ddfd1c20fa34 (patch)
tree272441de75567c13f2d6075b771b0fad2ab1ba5a /src
parentGive uIP a static IP address for proof-of-concept testing (diff)
downloadipxe-23c494d14efafdd1dd06cec53665ddfd1c20fa34.tar.gz
ipxe-23c494d14efafdd1dd06cec53665ddfd1c20fa34.tar.xz
ipxe-23c494d14efafdd1dd06cec53665ddfd1c20fa34.zip
Added basic code for implementing co-operative multitasking.
Yes, you really can do it in 65 bytes.
Diffstat (limited to 'src')
-rw-r--r--src/core/process.c56
-rw-r--r--src/include/gpxe/process.h32
2 files changed, 88 insertions, 0 deletions
diff --git a/src/core/process.c b/src/core/process.c
new file mode 100644
index 00000000..c087f16d
--- /dev/null
+++ b/src/core/process.c
@@ -0,0 +1,56 @@
+/*
+ * Copyright (C) 2006 Michael Brown <mbrown@fensystems.co.uk>.
+ *
+ * This program is free software; you can redistribute it and/or
+ * modify it under the terms of the GNU General Public License as
+ * published by the Free Software Foundation; either version 2 of the
+ * License, or any later version.
+ *
+ * This program is distributed in the hope that it will be useful, but
+ * WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
+ * General Public License for more details.
+ *
+ * You should have received a copy of the GNU General Public License
+ * along with this program; if not, write to the Free Software
+ * Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
+ */
+
+#include <gpxe/list.h>
+#include <gpxe/process.h>
+
+/** @file
+ *
+ * Processes
+ *
+ * We implement a trivial form of cooperative multitasking, in which
+ * all processes share a single stack and address space.
+ */
+
+/** Process run queue */
+static LIST_HEAD ( run_queue );
+
+/**
+ * Add process to run queue
+ *
+ * @v process Process
+ */
+void schedule ( struct process *process ) {
+ list_add_tail ( &process->list, &run_queue );
+}
+
+/**
+ * Single-step a single process
+ *
+ * This removes the first process from the run queue and executes a
+ * single step of that process.
+ */
+void step ( void ) {
+ struct process *process;
+
+ list_for_each_entry ( process, &run_queue, list ) {
+ list_del ( &process->list );
+ process->step ( process );
+ break;
+ }
+}
diff --git a/src/include/gpxe/process.h b/src/include/gpxe/process.h
new file mode 100644
index 00000000..83ff8393
--- /dev/null
+++ b/src/include/gpxe/process.h
@@ -0,0 +1,32 @@
+#ifndef _GPXE_PROCESS_H
+#define _GPXE_PROCESS_H
+
+/** @file
+ *
+ * Processes
+ *
+ */
+
+#include <gpxe/list.h>
+
+/** A process */
+struct process {
+ /** List of processes */
+ struct list_head list;
+ /**
+ * Single-step the process
+ *
+ * This method should execute a single step of the process.
+ * Returning from this method is isomorphic to yielding the
+ * CPU to another process.
+ *
+ * If the process wishes to be executed again, it must re-add
+ * itself to the run queue using schedule().
+ */
+ void ( * step ) ( struct process *process );
+};
+
+extern void schedule ( struct process *process );
+extern void step ( void );
+
+#endif /* _GPXE_PROCESS_H */