2 * Copyright (C) 2006 Michael Brown <mbrown@fensystems.co.uk>.
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.
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.
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.
19 #include <gpxe/list.h>
20 #include <gpxe/process.h>
26 * We implement a trivial form of cooperative multitasking, in which
27 * all processes share a single stack and address space.
30 /** Process run queue */
31 static LIST_HEAD ( run_queue );
34 * Add process to process list
38 void process_add ( struct process *process ) {
39 ref_get ( process->refcnt );
40 list_add_tail ( &process->list, &run_queue );
44 * Remove process from process list
48 * It is safe to call process_del() multiple times; further calls will
51 void process_del ( struct process *process ) {
52 if ( ! list_empty ( &process->list ) ) {
53 list_del ( &process->list );
54 INIT_LIST_HEAD ( &process->list );
55 ref_put ( process->refcnt );
60 * Single-step a single process
62 * This executes a single step of the first process in the run queue,
63 * and moves the process to the end of the run queue.
66 struct process *process;
68 list_for_each_entry ( process, &run_queue, list ) {
69 list_del ( &process->list );
70 list_add_tail ( &process->list, &run_queue );
71 process->step ( process );