From 04878ef74512df49803d1119c72c49cd8f1bfe10 Mon Sep 17 00:00:00 2001 From: Michael Brown Date: Mon, 10 Aug 2009 01:09:41 +0100 Subject: [process] Make it safe to call process_add() multiple times --- src/core/process.c | 13 ++++++++++--- src/include/gpxe/process.h | 1 + src/net/infiniband.c | 1 + src/net/netdevice.c | 1 + src/net/retry.c | 1 + 5 files changed, 14 insertions(+), 3 deletions(-) diff --git a/src/core/process.c b/src/core/process.c index 6dacd665..9c13e020 100644 --- a/src/core/process.c +++ b/src/core/process.c @@ -37,11 +37,18 @@ static LIST_HEAD ( run_queue ); * Add process to process list * * @v process Process + * + * It is safe to call process_add() multiple times; further calls will + * have no effect. */ void process_add ( struct process *process ) { - DBGC ( process, "PROCESS %p starting\n", process ); - ref_get ( process->refcnt ); - list_add_tail ( &process->list, &run_queue ); + if ( list_empty ( &process->list ) ) { + DBGC ( process, "PROCESS %p starting\n", process ); + ref_get ( process->refcnt ); + list_add_tail ( &process->list, &run_queue ); + } else { + DBGC ( process, "PROCESS %p already started\n", process ); + } } /** diff --git a/src/include/gpxe/process.h b/src/include/gpxe/process.h index a4609191..944858d7 100644 --- a/src/include/gpxe/process.h +++ b/src/include/gpxe/process.h @@ -47,6 +47,7 @@ static inline __attribute__ (( always_inline )) void process_init_stopped ( struct process *process, void ( * step ) ( struct process *process ), struct refcnt *refcnt ) { + INIT_LIST_HEAD ( &process->list ); process->step = step; process->refcnt = refcnt; } diff --git a/src/net/infiniband.c b/src/net/infiniband.c index 2d8b63ec..539c5290 100644 --- a/src/net/infiniband.c +++ b/src/net/infiniband.c @@ -802,6 +802,7 @@ static void ib_step ( struct process *process __unused ) { /** Infiniband event queue process */ struct process ib_process __permanent_process = { + .list = LIST_HEAD_INIT ( ib_process.list ), .step = ib_step, }; diff --git a/src/net/netdevice.c b/src/net/netdevice.c index e16ebaa0..3bb0574d 100644 --- a/src/net/netdevice.c +++ b/src/net/netdevice.c @@ -625,5 +625,6 @@ static void net_step ( struct process *process __unused ) { /** Networking stack process */ struct process net_process __permanent_process = { + .list = LIST_HEAD_INIT ( net_process.list ), .step = net_step, }; diff --git a/src/net/retry.c b/src/net/retry.c index 3ca69362..40f656f2 100644 --- a/src/net/retry.c +++ b/src/net/retry.c @@ -187,5 +187,6 @@ static void retry_step ( struct process *process __unused ) { /** Retry timer process */ struct process retry_process __permanent_process = { + .list = LIST_HEAD_INIT ( retry_process.list ), .step = retry_step, }; -- cgit v1.2.3-55-g7522