task.h 1.8 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657
  1. // SPDX-License-Identifier: GPL-2.0 or GPL-3.0
  2. // Copyright © 2018-2019 Ariadne Devos
  3. /* sHT -- things to do that may block */
  4. #ifndef _sHT_TASK_H
  5. #define _sHT_TASK_H
  6. #include <stddef.h>
  7. #include <stdint.h>
  8. #define sHT_TASK_QUEUED UINT32_C(1)
  9. #define sHT_TASK_SCHEDULE UINT32_C(1)
  10. /** Something to do that may block. If it would block, another task is run
  11. instead. It is automatically resumed. */
  12. struct sHT_task {
  13. /** Indicates which IO actions might be possible */
  14. uint32_t epollflags;
  15. /** @code{sHT_TASK_QUEUED}: this task is on a queue of things to
  16. do. It is automatically added by @var{sHT_qadd}.
  17. @code{sHT_TASK_SCHEDULE}: this task should be put on a queue
  18. of things to do. The queue and taskset code do not test,
  19. set or clear this flag.
  20. Feel free to add other flags of your own. */
  21. uint32_t flags;
  22. /** A pointer to the task to execute after this one, within a
  23. @var{sHT_taskset}. This should not be used outside taskset
  24. internals -- until this comment is changed to the contrary. */
  25. struct sHT_task *next;
  26. };
  27. /** Initialise the task @var{task}.
  28. This cleares its flags, and considers all IO actions to be potentially
  29. possible. @var{task} does not have to be initialised beforehand.
  30. @var{task} may not be concurrently acccessed.
  31. This cannot fail in any way. */
  32. __attribute__((nonnull(1)))
  33. static inline void
  34. sHT_init_task(struct sHT_task *task)
  35. {
  36. *task = (struct sHT_task) {
  37. .epollflags = ~UINT32_C(0),
  38. .flags = 0,
  39. /* TODO: in the Linux kernel, NULL is sometimes actually
  40. mapped and may therefore not be speculatively accessed.
  41. (In userspace, MMAP_PAGE_ZERO, to all zeros).
  42. On x86-64, AMD has promised never to allow mapping a
  43. certain range, use that in this case. */
  44. .next = NULL,
  45. };
  46. }
  47. #endif