mirror of
https://github.com/ipxe/ipxe
synced 2025-12-23 13:30:57 +03:00
[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>
This commit is contained in:
@@ -33,6 +33,16 @@ FILE_LICENCE ( GPL2_OR_LATER );
|
||||
/** Process run queue */
|
||||
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
|
||||
*
|
||||
@@ -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 */
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user