iPXE
Data Structures | Macros | 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...
 

Macros

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

Functions

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

Detailed Description

Processes.

Definition in file process.h.

Macro Definition Documentation

◆ PROC_STEP

#define PROC_STEP (   object_type,
  step 
)
Value:
( ( ( ( typeof ( step ) * ) NULL ) == \
( ( void ( * ) ( object_type *object ) ) NULL ) ) ? \
( void ( * ) ( void *object ) ) step : \
( void ( * ) ( void *object ) ) step )
void step(void)
Single-step a single process.
Definition: process.c:98
#define NULL
NULL pointer (VOID *)
Definition: Base.h:362

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.

◆ process_offset

#define process_offset (   object_type,
  name 
)
Value:
( ( ( ( typeof ( ( ( object_type * ) NULL )->name ) * ) NULL ) \
== ( ( struct process * ) NULL ) ) \
? offsetof ( object_type, name ) \
: offsetof ( object_type, name ) )
A process.
Definition: process.h:17
const char * name
Definition: ath9k_hw.c:1984
#define offsetof(type, field)
Get offset of a field within a structure.
Definition: stddef.h:24
#define NULL
NULL pointer (VOID *)
Definition: Base.h:362

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.

◆ PROC_DESC

#define PROC_DESC (   object_type,
  process,
  _step 
)
Value:
{ \
.name = #_step, \
.offset = process_offset ( object_type, process ), \
.step = PROC_STEP ( object_type, _step ), \
.reschedule = 1, \
}
A process.
Definition: process.h:17
#define PROC_STEP(object_type, step)
Define a process step() method.
Definition: process.h:55
#define process_offset(object_type, name)
Calculate offset of process within containing object.
Definition: process.h:68

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.

◆ PROC_DESC_ONCE

#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, \
}
A process.
Definition: process.h:17
#define PROC_STEP(object_type, step)
Define a process step() method.
Definition: process.h:55
#define process_offset(object_type, name)
Calculate offset of process within containing object.
Definition: process.h:68

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.

◆ PROC_DESC_PURE

#define PROC_DESC_PURE (   _step)
Value:
{ \
.name = #_step, \
.offset = 0, \
.step = PROC_STEP ( struct process, _step ), \
.reschedule = 1, \
}
A process.
Definition: process.h:17
#define PROC_STEP(object_type, step)
Define a process step() method.
Definition: process.h:55

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.

◆ PROC_INIT

#define PROC_INIT (   _process,
  _desc 
)
Value:
{ \
.list = LIST_HEAD_INIT ( (_process).list ), \
.desc = (_desc), \
.refcnt = NULL, \
}
struct list_head list
List of processes.
Definition: process.h:19
A reference counter.
Definition: refcnt.h:26
#define LIST_HEAD_INIT(list)
Initialise a static list head.
Definition: list.h:30
#define NULL
NULL pointer (VOID *)
Definition: Base.h:362

Initialise a static process.

Parameters
processProcess
descProcess descriptor

Definition at line 131 of file process.h.

◆ PERMANENT_PROCESSES

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

Permanent process table.

Definition at line 180 of file process.h.

◆ __permanent_process

#define __permanent_process   __table_entry ( PERMANENT_PROCESSES, 01 )

Declare a permanent process.

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

Definition at line 188 of file process.h.

◆ PERMANENT_PROCESS

#define PERMANENT_PROCESS (   name,
  step 
)
Value:
static struct process_descriptor name ## _desc = PROC_DESC_PURE ( step ); \
A process.
Definition: process.h:17
const char * name
Definition: ath9k_hw.c:1984
A process descriptor.
Definition: process.h:31
#define PROC_INIT(_process, _desc)
Initialise a static process.
Definition: process.h:131
#define __permanent_process
Declare a permanent process.
Definition: process.h:188
#define PROC_DESC_PURE(_step)
Define a process descriptor for a pure process.
Definition: process.h:112
void step(void)
Single-step a single process.
Definition: process.c:98

Define a permanent process.

Definition at line 193 of file process.h.

◆ PROC_COL

#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 205 of file process.h.

◆ PROC_FMT

#define PROC_FMT   "%p %s()"

printf() format string for PROC_DBG()

Definition at line 208 of file process.h.

◆ PROC_DBG

#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 216 of file process.h.

Function Documentation

◆ FILE_LICENCE()

FILE_LICENCE ( GPL2_OR_LATER_OR_UBDL  )

◆ process_object()

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.

47  {
48  return ( ( ( void * ) process ) - process->desc->offset );
49 }
A process.
Definition: process.h:17
size_t offset
Offset of process within containing object.
Definition: process.h:35
struct process_descriptor * desc
Process descriptor.
Definition: process.h:21

References process::desc, and process_descriptor::offset.

Referenced by step().

◆ process_add()

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.

59  {
60  if ( ! process_running ( process ) ) {
61  DBGC ( PROC_COL ( process ), "PROCESS " PROC_FMT
62  " starting\n", PROC_DBG ( process ) );
63  ref_get ( process->refcnt );
64  list_add_tail ( &process->list, &run_queue );
65  } else {
66  DBGC ( PROC_COL ( process ), "PROCESS " PROC_FMT
67  " already started\n", PROC_DBG ( process ) );
68  }
69 }
A process.
Definition: process.h:17
#define DBGC(...)
Definition: compiler.h:505
struct list_head list
List of processes.
Definition: process.h:19
#define list_add_tail(new, head)
Add a new entry to the tail of a list.
Definition: list.h:93
#define ref_get(refcnt)
Get additional reference to object.
Definition: refcnt.h:92
static int process_running(struct process *process)
Check if process is running.
Definition: process.h:175
#define PROC_DBG(process)
printf() arguments for representing a process
Definition: process.h:216
#define PROC_COL(process)
Find debugging colourisation for a process.
Definition: process.h:205
#define PROC_FMT
printf() format string for PROC_DBG()
Definition: process.h:208
struct refcnt * refcnt
Reference counter.
Definition: process.h:27

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_dequeue(), peerblk_enqueue(), peerblk_retrieval_close(), peerblk_step(), 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().

◆ process_del()

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.

79  {
80  if ( process_running ( process ) ) {
81  DBGC ( PROC_COL ( process ), "PROCESS " PROC_FMT
82  " stopping\n", PROC_DBG ( process ) );
83  list_del ( &process->list );
85  ref_put ( process->refcnt );
86  } else {
87  DBGC ( PROC_COL ( process ), "PROCESS " PROC_FMT
88  " already stopped\n", PROC_DBG ( process ) );
89  }
90 }
A process.
Definition: process.h:17
#define DBGC(...)
Definition: compiler.h:505
struct list_head list
List of processes.
Definition: process.h:19
#define list_del(list)
Delete an entry from a list.
Definition: list.h:119
static int process_running(struct process *process)
Check if process is running.
Definition: process.h:175
#define INIT_LIST_HEAD(list)
Initialise a list head.
Definition: list.h:45
#define PROC_DBG(process)
printf() arguments for representing a process
Definition: process.h:216
#define PROC_COL(process)
Find debugging colourisation for a process.
Definition: process.h:205
#define PROC_FMT
printf() format string for PROC_DBG()
Definition: process.h:208
struct refcnt * refcnt
Reference counter.
Definition: process.h:27
#define ref_put(refcnt)
Drop reference to object.
Definition: refcnt.h:106

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().

◆ step()

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.

98  {
99  struct process *process;
100  struct process_descriptor *desc;
101  void *object;
102 
103  if ( ( process = list_first_entry ( &run_queue, struct process,
104  list ) ) ) {
105  ref_get ( process->refcnt ); /* Inhibit destruction mid-step */
106  desc = process->desc;
107  object = process_object ( process );
108  if ( desc->reschedule ) {
109  list_del ( &process->list );
110  list_add_tail ( &process->list, &run_queue );
111  } else {
112  process_del ( process );
113  }
114  DBGC2 ( PROC_COL ( process ), "PROCESS " PROC_FMT
115  " executing\n", PROC_DBG ( process ) );
116  desc->step ( object );
117  DBGC2 ( PROC_COL ( process ), "PROCESS " PROC_FMT
118  " finished executing\n", PROC_DBG ( process ) );
119  ref_put ( process->refcnt ); /* Allow destruction */
120  }
121 }
A process.
Definition: process.h:17
A process descriptor.
Definition: process.h:31
struct list_head list
List of processes.
Definition: process.h:19
void process_del(struct process *process)
Remove process from process list.
Definition: process.c:79
#define list_first_entry(list, type, member)
Get the container of the first entry in a list.
Definition: list.h:333
#define list_del(list)
Delete an entry from a list.
Definition: list.h:119
void * process_object(struct process *process)
Get pointer to object containing process.
Definition: process.c:47
#define list_add_tail(new, head)
Add a new entry to the tail of a list.
Definition: list.h:93
#define ref_get(refcnt)
Get additional reference to object.
Definition: refcnt.h:92
#define PROC_DBG(process)
printf() arguments for representing a process
Definition: process.h:216
#define DBGC2(...)
Definition: compiler.h:522
int reschedule
Automatically reschedule the process.
Definition: process.h:45
struct process_descriptor * desc
Process descriptor.
Definition: process.h:21
#define PROC_COL(process)
Find debugging colourisation for a process.
Definition: process.h:205
#define PROC_FMT
printf() format string for PROC_DBG()
Definition: process.h:208
void(* step)(void *object)
Single-step the process.
Definition: process.h:43
struct refcnt * refcnt
Reference counter.
Definition: process.h:27
#define ref_put(refcnt)
Drop reference to object.
Definition: refcnt.h:106

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(), gdbmach_set_single_step(), 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().

◆ process_init_stopped()

static void process_init_stopped ( struct process process,
struct process_descriptor desc,
struct refcnt refcnt 
)
inlinestatic

Initialise process without adding to process list.

Parameters
processProcess
descProcess descriptor
refcntContaining object reference count, or NULL

Definition at line 145 of file process.h.

147  {
149  process->desc = desc;
150  process->refcnt = refcnt;
151 }
A process.
Definition: process.h:17
struct list_head list
List of processes.
Definition: process.h:19
static void(*) struct refcnt refcnt)
Definition: pool.h:62
#define INIT_LIST_HEAD(list)
Initialise a list head.
Definition: list.h:45
struct process_descriptor * desc
Process descriptor.
Definition: process.h:21
struct refcnt * refcnt
Reference counter.
Definition: process.h:27

References process::desc, INIT_LIST_HEAD, process::list, process::refcnt, and refcnt.

Referenced by add_tls(), 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().

◆ process_init()

static void process_init ( struct process process,
struct process_descriptor desc,
struct refcnt refcnt 
)
inlinestatic

Initialise process and add to process list.

Parameters
processProcess
descProcess descriptor
refcntContaining object reference count, or NULL

Definition at line 161 of file process.h.

163  {
165  process_add ( process );
166 }
A process.
Definition: process.h:17
A reference counter.
Definition: refcnt.h:26
void process_add(struct process *process)
Add process to process list.
Definition: process.c:59
static void process_init_stopped(struct process *process, struct process_descriptor *desc, struct refcnt *refcnt)
Initialise process without adding to process list.
Definition: process.h:145

References process_add(), and process_init_stopped().

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

◆ process_running()

static int process_running ( struct process process)
inlinestatic

Check if process is running.

Parameters
processProcess
Return values
runningProcess is running

Definition at line 175 of file process.h.

175  {
176  return ( ! list_empty ( &process->list ) );
177 }
A process.
Definition: process.h:17
struct list_head list
List of processes.
Definition: process.h:19
#define list_empty(list)
Test whether a list is empty.
Definition: list.h:136

References process::list, and 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().