aboutsummaryrefslogtreecommitdiffstats
path: root/gpxe/src/include/gpxe/process.h
blob: 8d9b109a5f6ef23e6514147ba047c871a277efb0 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
#ifndef _GPXE_PROCESS_H
#define _GPXE_PROCESS_H

/** @file
 *
 * Processes
 *
 */

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

/** A process */
struct process {
	/** List of processes */
	struct list_head list;
	/**
	 * Single-step the process
	 *
	 * This method should execute a single step of the process.
	 * Returning from this method is isomorphic to yielding the
	 * CPU to another process.
	 */
	void ( * step ) ( struct process *process );
	/** Reference counter
	 *
	 * If this interface is not part of a reference-counted
	 * object, this field may be NULL.
	 */
	struct refcnt *refcnt;
};

extern void process_add ( struct process *process );
extern void process_del ( struct process *process );
extern void step ( void );

/**
 * Initialise process without adding to process list
 *
 * @v process		Process
 * @v step		Process' step() method
 */
static inline __attribute__ (( always_inline )) void
process_init_stopped ( struct process *process,
		       void ( * step ) ( struct process *process ),
		       struct refcnt *refcnt ) {
	process->step = step;
	process->refcnt = refcnt;
}

/**
 * Initialise process and add to process list
 *
 * @v process		Process
 * @v step		Process' step() method
 */
static inline __attribute__ (( always_inline )) void
process_init ( struct process *process,
	       void ( * step ) ( struct process *process ),
	       struct refcnt *refcnt ) {
	process_init_stopped ( process, step, refcnt );
	process_add ( process );
}

/**
 * Declare a permanent process
 *
 * Permanent processes will be automatically added to the process list
 * at initialisation time.
 */
#define __permanent_process \
	__table ( struct process, processes, 01 )

#endif /* _GPXE_PROCESS_H */