Browse Source

[process] Add support for one-shot processes

Some processes execute only once, and exist solely in order to defer
execution until after the relevant instantiator method has returned.
Such processes do not need to be automatically rescheduled when
executing.

Signed-off-by: Michael Brown <mcb30@ipxe.org>
tags/v1.20.1
Michael Brown 13 years ago
parent
commit
ccc2655540
2 changed files with 24 additions and 2 deletions
  1. 6
    2
      src/core/process.c
  2. 18
    0
      src/include/ipxe/process.h

+ 6
- 2
src/core/process.c View File

@@ -100,8 +100,12 @@ void step ( void ) {
100 100
 		ref_get ( process->refcnt ); /* Inhibit destruction mid-step */
101 101
 		desc = process->desc;
102 102
 		object = process_object ( process );
103
-		list_del ( &process->list );
104
-		list_add_tail ( &process->list, &run_queue );
103
+		if ( desc->reschedule ) {
104
+			list_del ( &process->list );
105
+			list_add_tail ( &process->list, &run_queue );
106
+		} else {
107
+			process_del ( process );
108
+		}
105 109
 		DBGC2 ( PROC_COL ( process ), "PROCESS " PROC_FMT
106 110
 			" executing\n", PROC_DBG ( process ) );
107 111
 		desc->step ( object );

+ 18
- 0
src/include/ipxe/process.h View File

@@ -39,6 +39,8 @@ struct process_descriptor {
39 39
 	 * CPU to another process.
40 40
 	 */
41 41
 	void ( * step ) ( void *object );
42
+	/** Automatically reschedule the process */
43
+	int reschedule;
42 44
 };
43 45
 
44 46
 /**
@@ -78,6 +80,21 @@ struct process_descriptor {
78 80
 #define PROC_DESC( object_type, process, _step ) {			      \
79 81
 		.offset = process_offset ( object_type, process ),	      \
80 82
 		.step = PROC_STEP ( object_type, _step ),		      \
83
+		.reschedule = 1,					      \
84
+	}
85
+
86
+/**
87
+ * Define a process descriptor for a process that runs only once
88
+ *
89
+ * @v object_type	Containing object data type
90
+ * @v process		Process name (i.e. field within object data type)
91
+ * @v step		Process' step() method
92
+ * @ret desc		Object interface descriptor
93
+ */
94
+#define PROC_DESC_ONCE( object_type, process, _step ) {			      \
95
+		.offset = process_offset ( object_type, process ),	      \
96
+		.step = PROC_STEP ( object_type, _step ),		      \
97
+		.reschedule = 0,					      \
81 98
 	}
82 99
 
83 100
 /**
@@ -91,6 +108,7 @@ struct process_descriptor {
91 108
 #define PROC_DESC_PURE( _step ) {					      \
92 109
 		.offset = 0,						      \
93 110
 		.step = PROC_STEP ( struct process, _step ),		      \
111
+		.reschedule = 1,					      \
94 112
 	}
95 113
 
96 114
 extern void * __attribute__ (( pure ))

Loading…
Cancel
Save