You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

process.h 1.9KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980
  1. #ifndef _GPXE_PROCESS_H
  2. #define _GPXE_PROCESS_H
  3. /** @file
  4. *
  5. * Processes
  6. *
  7. */
  8. FILE_LICENCE ( GPL2_OR_LATER );
  9. #include <gpxe/list.h>
  10. #include <gpxe/refcnt.h>
  11. #include <gpxe/tables.h>
  12. /** A process */
  13. struct process {
  14. /** List of processes */
  15. struct list_head list;
  16. /**
  17. * Single-step the process
  18. *
  19. * This method should execute a single step of the process.
  20. * Returning from this method is isomorphic to yielding the
  21. * CPU to another process.
  22. */
  23. void ( * step ) ( struct process *process );
  24. /** Reference counter
  25. *
  26. * If this interface is not part of a reference-counted
  27. * object, this field may be NULL.
  28. */
  29. struct refcnt *refcnt;
  30. };
  31. extern void process_add ( struct process *process );
  32. extern void process_del ( struct process *process );
  33. extern void step ( void );
  34. /**
  35. * Initialise process without adding to process list
  36. *
  37. * @v process Process
  38. * @v step Process' step() method
  39. */
  40. static inline __attribute__ (( always_inline )) void
  41. process_init_stopped ( struct process *process,
  42. void ( * step ) ( struct process *process ),
  43. struct refcnt *refcnt ) {
  44. INIT_LIST_HEAD ( &process->list );
  45. process->step = step;
  46. process->refcnt = refcnt;
  47. }
  48. /**
  49. * Initialise process and add to process list
  50. *
  51. * @v process Process
  52. * @v step Process' step() method
  53. */
  54. static inline __attribute__ (( always_inline )) void
  55. process_init ( struct process *process,
  56. void ( * step ) ( struct process *process ),
  57. struct refcnt *refcnt ) {
  58. process_init_stopped ( process, step, refcnt );
  59. process_add ( process );
  60. }
  61. /** Permanent process table */
  62. #define PERMANENT_PROCESSES __table ( struct process, "processes" )
  63. /**
  64. * Declare a permanent process
  65. *
  66. * Permanent processes will be automatically added to the process list
  67. * at initialisation time.
  68. */
  69. #define __permanent_process __table_entry ( PERMANENT_PROCESSES, 01 )
  70. #endif /* _GPXE_PROCESS_H */