diff options
| author | Michael Brown | 2011-06-24 15:14:41 +0200 |
|---|---|---|
| committer | Michael Brown | 2011-06-28 15:45:08 +0200 |
| commit | e01ec74601b58f54a5e2ae7b9fd1196972034114 (patch) | |
| tree | 54f2d2202274523e2365584502dee7db8deca43b /src/core | |
| parent | [xfer] Send xfer_window_changed() after xfer_vredirect() (diff) | |
| download | ipxe-e01ec74601b58f54a5e2ae7b9fd1196972034114.tar.gz ipxe-e01ec74601b58f54a5e2ae7b9fd1196972034114.tar.xz ipxe-e01ec74601b58f54a5e2ae7b9fd1196972034114.zip | |
[process] Pass containing object pointer to process step() methods
Give the step() method a pointer to the containing object, rather than
a pointer to the process. This is consistent with the operation of
interface methods, and allows a single function to serve as both an
interface method and a process step() method.
Signed-off-by: Michael Brown <mcb30@ipxe.org>
Diffstat (limited to 'src/core')
| -rw-r--r-- | src/core/hw.c | 22 | ||||
| -rw-r--r-- | src/core/process.c | 42 | ||||
| -rw-r--r-- | src/core/resolv.c | 12 |
3 files changed, 47 insertions, 29 deletions
diff --git a/src/core/hw.c b/src/core/hw.c index aca558099..e9c9ffc1d 100644 --- a/src/core/hw.c +++ b/src/core/hw.c @@ -26,15 +26,7 @@ static void hw_finished ( struct hw *hw, int rc ) { process_del ( &hw->process ); } -static struct interface_operation hw_xfer_operations[] = { - INTF_OP ( intf_close, struct hw *, hw_finished ), -}; - -static struct interface_descriptor hw_xfer_desc = - INTF_DESC ( struct hw, xfer, hw_xfer_operations ); - -static void hw_step ( struct process *process ) { - struct hw *hw = container_of ( process, struct hw, process ); +static void hw_step ( struct hw *hw ) { int rc; if ( xfer_window ( &hw->xfer ) ) { @@ -43,6 +35,16 @@ static void hw_step ( struct process *process ) { } } +static struct interface_operation hw_xfer_operations[] = { + INTF_OP ( intf_close, struct hw *, hw_finished ), +}; + +static struct interface_descriptor hw_xfer_desc = + INTF_DESC ( struct hw, xfer, hw_xfer_operations ); + +static struct process_descriptor hw_process_desc = + PROC_DESC ( struct hw, process, hw_step ); + static int hw_open ( struct interface *xfer, struct uri *uri __unused ) { struct hw *hw; @@ -52,7 +54,7 @@ static int hw_open ( struct interface *xfer, struct uri *uri __unused ) { return -ENOMEM; ref_init ( &hw->refcnt, NULL ); intf_init ( &hw->xfer, &hw_xfer_desc, &hw->refcnt ); - process_init ( &hw->process, hw_step, &hw->refcnt ); + process_init ( &hw->process, &hw_process_desc, &hw->refcnt ); /* Attach parent interface, mortalise self, and return */ intf_plug_plug ( &hw->xfer, xfer ); diff --git a/src/core/process.c b/src/core/process.c index a32978564..c6660f227 100644 --- a/src/core/process.c +++ b/src/core/process.c @@ -34,6 +34,16 @@ FILE_LICENCE ( GPL2_OR_LATER ); static LIST_HEAD ( run_queue ); /** + * Get pointer to object containing process + * + * @v process Process + * @ret object Containing object + */ +void * process_object ( struct process *process ) { + return ( ( ( void * ) process ) - process->desc->offset ); +} + +/** * Add process to process list * * @v process Process @@ -43,13 +53,13 @@ static LIST_HEAD ( run_queue ); */ void process_add ( struct process *process ) { if ( ! process_running ( process ) ) { - DBGC ( process, "PROCESS %p (%p) starting\n", - process, process->step ); + DBGC ( PROC_COL ( process ), "PROCESS " PROC_FMT + " starting\n", PROC_DBG ( process ) ); ref_get ( process->refcnt ); list_add_tail ( &process->list, &run_queue ); } else { - DBGC ( process, "PROCESS %p (%p) already started\n", - process, process->step ); + DBGC ( PROC_COL ( process ), "PROCESS " PROC_FMT + " already started\n", PROC_DBG ( process ) ); } } @@ -63,14 +73,14 @@ void process_add ( struct process *process ) { */ void process_del ( struct process *process ) { if ( process_running ( process ) ) { - DBGC ( process, "PROCESS %p (%p) stopping\n", - process, process->step ); + DBGC ( PROC_COL ( process ), "PROCESS " PROC_FMT + " stopping\n", PROC_DBG ( process ) ); list_del ( &process->list ); INIT_LIST_HEAD ( &process->list ); ref_put ( process->refcnt ); } else { - DBGC ( process, "PROCESS %p (%p) already stopped\n", - process, process->step ); + DBGC ( PROC_COL ( process ), "PROCESS " PROC_FMT + " already stopped\n", PROC_DBG ( process ) ); } } @@ -82,17 +92,21 @@ void process_del ( struct process *process ) { */ void step ( void ) { struct process *process; + struct process_descriptor *desc; + void *object; if ( ( process = list_first_entry ( &run_queue, struct process, list ) ) ) { + ref_get ( process->refcnt ); /* Inhibit destruction mid-step */ + desc = process->desc; + object = process_object ( process ); list_del ( &process->list ); list_add_tail ( &process->list, &run_queue ); - ref_get ( process->refcnt ); /* Inhibit destruction mid-step */ - DBGC2 ( process, "PROCESS %p (%p) executing\n", - process, process->step ); - process->step ( process ); - DBGC2 ( process, "PROCESS %p (%p) finished executing\n", - process, process->step ); + DBGC2 ( PROC_COL ( process ), "PROCESS " PROC_FMT + " executing\n", PROC_DBG ( process ) ); + desc->step ( object ); + DBGC2 ( PROC_COL ( process ), "PROCESS " PROC_FMT + " finished executing\n", PROC_DBG ( process ) ); ref_put ( process->refcnt ); /* Allow destruction */ } } diff --git a/src/core/resolv.c b/src/core/resolv.c index 91f0c15ce..9edfceadc 100644 --- a/src/core/resolv.c +++ b/src/core/resolv.c @@ -86,16 +86,17 @@ struct numeric_resolv { int rc; }; -static void numeric_step ( struct process *process ) { - struct numeric_resolv *numeric = - container_of ( process, struct numeric_resolv, process ); +static void numeric_step ( struct numeric_resolv *numeric ) { - process_del ( process ); + process_del ( &numeric->process ); if ( numeric->rc == 0 ) resolv_done ( &numeric->resolv, &numeric->sa ); intf_shutdown ( &numeric->resolv, numeric->rc ); } +static struct process_descriptor numeric_process_desc = + PROC_DESC ( struct numeric_resolv, process, numeric_step ); + static int numeric_resolv ( struct interface *resolv, const char *name, struct sockaddr *sa ) { struct numeric_resolv *numeric; @@ -107,7 +108,8 @@ static int numeric_resolv ( struct interface *resolv, return -ENOMEM; ref_init ( &numeric->refcnt, NULL ); intf_init ( &numeric->resolv, &null_intf_desc, &numeric->refcnt ); - process_init ( &numeric->process, numeric_step, &numeric->refcnt ); + process_init ( &numeric->process, &numeric_process_desc, + &numeric->refcnt ); memcpy ( &numeric->sa, sa, sizeof ( numeric->sa ) ); DBGC ( numeric, "NUMERIC %p attempting to resolve \"%s\"\n", |
