iPXE
Data Structures | Defines | Functions
process.h File Reference

Processes. More...

#include <ipxe/list.h>
#include <ipxe/refcnt.h>
#include <ipxe/tables.h>

Go to the source code of this file.

Data Structures

struct  process
 A process. More...
struct  process_descriptor
 A process descriptor. More...

Defines

#define PROC_STEP(object_type, step)
 Define a process step() method.
#define process_offset(object_type, name)
 Calculate offset of process within containing object.
#define PROC_DESC(object_type, process, _step)
 Define a process descriptor.
#define PROC_DESC_ONCE(object_type, process, _step)
 Define a process descriptor for a process that runs only once.
#define PROC_DESC_PURE(_step)
 Define a process descriptor for a pure process.
#define PERMANENT_PROCESSES   __table ( struct process, "processes" )
 Permanent process table.
#define __permanent_process   __table_entry ( PERMANENT_PROCESSES, 01 )
 Declare a permanent process.
#define PERMANENT_PROCESS(name, step)
 Define a permanent process.
#define PROC_COL(process)   process_object ( process )
 Find debugging colourisation for a process.
#define PROC_FMT   "%p %s()"
 printf() format string for PROC_DBG()
#define PROC_DBG(process)   process_object ( process ), (process)->desc->name
 printf() arguments for representing a process

Functions

 FILE_LICENCE (GPL2_OR_LATER_OR_UBDL)
void * process_object (struct process *process)
 Get pointer to object containing process.
void process_add (struct process *process)
 Add process to process list.
void process_del (struct process *process)
 Remove process from process list.
void step (void)
 Single-step a single process.
static void process_init_stopped (struct process *process, struct process_descriptor *desc, struct refcnt *refcnt)
 Initialise process without adding to process list.
static void process_init (struct process *process, struct process_descriptor *desc, struct refcnt *refcnt)
 Initialise process and add to process list.
static int process_running (struct process *process)
 Check if process is running.

Detailed Description

Processes.

Definition in file process.h.


Define Documentation

#define PROC_STEP (   object_type,
  step 
)
Value:
( ( ( ( typeof ( step ) * ) NULL ) ==                                 \
            ( ( void ( * ) ( object_type *object ) ) NULL ) ) ?               \
          ( void ( * ) ( void *object ) ) step :                              \
          ( void ( * ) ( void *object ) ) step )

Define a process step() method.

Parameters:
object_typeImplementing method's expected object type
stepImplementing method
Return values:
stepProcess step method

Definition at line 55 of file process.h.

#define process_offset (   object_type,
  name 
)
Value:
( ( ( ( typeof ( ( ( object_type * ) NULL )->name ) * ) NULL )        \
            == ( ( struct process * ) NULL ) )                                \
          ? offsetof ( object_type, name )                                    \
          : offsetof ( object_type, name ) )

Calculate offset of process within containing object.

Parameters:
object_typeContaining object data type
nameProcess name (i.e. field within object data type)
Return values:
offsetOffset of process within containing object

Definition at line 68 of file process.h.

#define PROC_DESC (   object_type,
  process,
  _step 
)
Value:
{                             \
                .name = #_step,                                               \
                .offset = process_offset ( object_type, process ),            \
                .step = PROC_STEP ( object_type, _step ),                     \
                .reschedule = 1,                                              \
        }

Define a process descriptor.

Parameters:
object_typeContaining object data type
processProcess name (i.e. field within object data type)
stepProcess' step() method
Return values:
descObject interface descriptor

Definition at line 82 of file process.h.

#define PROC_DESC_ONCE (   object_type,
  process,
  _step 
)
Value:
{                             \
                .name = #_step,                                               \
                .offset = process_offset ( object_type, process ),            \
                .step = PROC_STEP ( object_type, _step ),                     \
                .reschedule = 0,                                              \
        }

Define a process descriptor for a process that runs only once.

Parameters:
object_typeContaining object data type
processProcess name (i.e. field within object data type)
stepProcess' step() method
Return values:
descObject interface descriptor

Definition at line 97 of file process.h.

#define PROC_DESC_PURE (   _step)
Value:
{                                             \
                .name = #_step,                                               \
                .offset = 0,                                                  \
                .step = PROC_STEP ( struct process, _step ),                  \
                .reschedule = 1,                                              \
        }

Define a process descriptor for a pure process.

A pure process is a process that does not have a containing object.

Parameters:
stepProcess' step() method
Return values:
descObject interface descriptor

Definition at line 112 of file process.h.

#define PERMANENT_PROCESSES   __table ( struct process, "processes" )

Permanent process table.

Definition at line 168 of file process.h.

Referenced by init_processes().

Declare a permanent process.

Permanent processes will be automatically added to the process list at initialisation time.

Definition at line 176 of file process.h.

#define PERMANENT_PROCESS (   name,
  step 
)
Value:
static struct process_descriptor name ## _desc = PROC_DESC_PURE ( step );     \
struct process name __permanent_process = {                                   \
        .list = LIST_HEAD_INIT ( name.list ),                                 \
        .desc = & name ## _desc,                                              \
        .refcnt = NULL,                                                       \
};

Define a permanent process.

Definition at line 181 of file process.h.

#define PROC_COL (   process)    process_object ( process )

Find debugging colourisation for a process.

Parameters:
processProcess
Return values:
colDebugging colourisation

Use as the first argument to DBGC() or equivalent macro.

Definition at line 197 of file process.h.

Referenced by process_add(), process_del(), and step().

#define PROC_FMT   "%p %s()"

printf() format string for PROC_DBG()

Definition at line 200 of file process.h.

Referenced by process_add(), process_del(), and step().

#define PROC_DBG (   process)    process_object ( process ), (process)->desc->name

printf() arguments for representing a process

Parameters:
processProcess
Return values:
argsprintf() argument list corresponding to PROC_FMT

Definition at line 208 of file process.h.

Referenced by process_add(), process_del(), and step().


Function Documentation

FILE_LICENCE ( GPL2_OR_LATER_OR_UBDL  )
void* process_object ( struct process process)

Get pointer to object containing process.

Parameters:
processProcess
Return values:
objectContaining object

Definition at line 47 of file process.c.

Referenced by step().

                                                  {
        return ( ( ( void * ) process ) - process->desc->offset );
}
void process_add ( struct process process)

Add process to process list.

Parameters:
processProcess

It is safe to call process_add() multiple times; further calls will have no effect.

Definition at line 59 of file process.c.

References DBGC, process::list, list_add_tail, PROC_COL, PROC_DBG, PROC_FMT, process_running(), ref_get, and process::refcnt.

Referenced by efi_pxe_udp_schedule_close(), fc_els_request(), fcpcmd_start_send(), http_reopen(), hub_complete(), hub_open(), ib_cmrc_close(), init_processes(), iscsi_tx_resume(), net80211_autoassociate(), peerblk_retrieval_close(), peermux_block_close(), peermux_info_close(), process_init(), sanpath_open(), scsidev_ready(), tcp_close(), tcp_rx(), tls_tx_resume(), validator_xfer_close(), and xcm_reopen().

                                             {
        if ( ! process_running ( process ) ) {
                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 ( PROC_COL ( process ), "PROCESS " PROC_FMT
                       " already started\n", PROC_DBG ( process ) );
        }
}
void process_del ( struct process process)

Remove process from process list.

Parameters:
processProcess

It is safe to call process_del() multiple times; further calls will have no effect.

Definition at line 79 of file process.c.

References DBGC, INIT_LIST_HEAD, process::list, list_del, PROC_COL, PROC_DBG, PROC_FMT, process_running(), ref_put, and process::refcnt.

Referenced by efi_local_close(), efi_pxe_udp_close(), efi_pxe_udp_open(), fc_els_close(), fc_ns_query_close(), fcpcmd_stop_send(), http_close(), hub_close(), hub_refill(), hw_finished(), ib_cmrc_shutdown(), iscsi_close(), iscsi_tx_pause(), net80211_netdev_close(), net80211_step_associate(), peerblk_reset(), peermux_close(), peermux_step(), sanpath_close(), scsidev_close(), step(), tcp_close(), tls_close(), validator_finished(), xcm_close(), xcm_destroy(), and xcm_reopen().

                                             {
        if ( process_running ( process ) ) {
                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 ( PROC_COL ( process ), "PROCESS " PROC_FMT
                       " already stopped\n", PROC_DBG ( process ) );
        }
}
void step ( void  )

Single-step a single process.

This executes a single step of the first process in the run queue, and moves the process to the end of the run queue.

Definition at line 98 of file process.c.

References DBGC2, process::desc, process::list, list_add_tail, list_del, list_first_entry, PROC_COL, PROC_DBG, PROC_FMT, process_del(), process_object(), ref_get, ref_put, process::refcnt, process_descriptor::reschedule, and process_descriptor::step.

Referenced by ath5k_hw_rf_check_gainf_readback(), ath5k_hw_rf_gainf_corr(), comboot_resolv(), efi_download_poll(), efi_ifr_numeric_op(), efi_pxe_dhcp(), efi_pxe_mtftp(), efi_pxe_udp_read(), getchar(), getchar_timeout(), int22(), iwlist(), md4_digest(), md5_digest(), monojob_wait(), open(), pxenv_tftp_get_fsize(), pxenv_tftp_open(), pxenv_tftp_read(), pxenv_tftp_read_file(), pxenv_udp_read(), read_user(), sandev_command(), sandev_describe(), sandev_reopen(), select(), sha1_digest(), sleep_interruptible(), spi_bit_transfer(), and tcp_shutdown().

                   {
        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 );
                if ( desc->reschedule ) {
                        list_del ( &process->list );
                        list_add_tail ( &process->list, &run_queue );
                } else {
                        process_del ( process );
                }
                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 */
        }
}
static void process_init_stopped ( struct process process,
struct process_descriptor desc,
struct refcnt refcnt 
) [inline, static]

Initialise process without adding to process list.

Parameters:
processProcess
descProcess descriptor
refcntContaining object reference count, or NULL

Definition at line 133 of file process.h.

References INIT_LIST_HEAD.

Referenced by alloc_sandev(), efi_pxe_install(), fc_els_create(), fcpdev_scsi_command(), hub_probe(), ib_cmrc_open(), iscsi_open(), net80211_alloc(), peerblk_open(), peermux_filter(), process_init(), tcp_open(), and xcm_create().

                                               {
        INIT_LIST_HEAD ( &process->list );
        process->desc = desc;
        process->refcnt = refcnt;
}
static void process_init ( struct process process,
struct process_descriptor desc,
struct refcnt refcnt 
) [inline, static]

Initialise process and add to process list.

Parameters:
processProcess
descProcess descriptor
refcntContaining object reference count, or NULL

Definition at line 149 of file process.h.

References process_add(), and process_init_stopped().

Referenced by add_tls(), create_validator(), efi_local_open(), fc_ns_query(), http_open(), hw_open(), numeric_resolv(), and scsi_open().

                                       {
        process_init_stopped ( process, desc, refcnt );
        process_add ( process );
}
static int process_running ( struct process process) [inline, static]

Check if process is running.

Parameters:
processProcess
Return values:
runningProcess is running

Definition at line 163 of file process.h.

References list_empty.

Referenced by efi_pxe_udp_close(), efi_pxe_udp_open(), fc_els_free(), hub_remove(), process_add(), process_del(), tcp_first_unfinished(), and xcm_free().

                                            {
        return ( ! list_empty ( &process->list ) );
}