task.h 2.3 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869
  1. /* shttpd - tasks
  2. Copyright (C) 2018 Ariadne Devos
  3. This program is free software: you can redistribute it and/or modify
  4. it under the terms of the GNU General Public License as published by
  5. the Free Software Foundation, either version 3 of the License, or
  6. (at your option) any later version.
  7. This program is distributed in the hope that it will be useful,
  8. but WITHOUT ANY WARRANTY; without even the implied warranty of
  9. MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
  10. GNU General Public License for more details.
  11. You should have received a copy of the GNU General Public License
  12. along with this program. If not, see <http://www.gnu.org/licenses/>. */
  13. #ifndef _sHT_TASK_H
  14. #define _sHT_TASK_H
  15. #include <stddef.h>
  16. #include <stdint.h>
  17. #define sHT_TASK_QUEUED UINT32_C(1)
  18. #define sHT_TASK_SCHEDULE UINT32_C(1)
  19. /** Something to do that may block. If it would block, another task is run
  20. instead. It is automatically resumed. */
  21. struct sHT_task {
  22. /** Indicates which IO actions might be possible */
  23. uint32_t epollflags;
  24. /** @code{sHT_TASK_QUEUED}: this task is on a queue of things to
  25. do. It is automatically added by @var{sHT_qadd}.
  26. @code{sHT_TASK_SCHEDULE}: this task should be put on a queue
  27. of things to do. The queue and taskset code do not test,
  28. set or clear this flag.
  29. Feel free to add other flags of your own. */
  30. uint32_t flags;
  31. /** A pointer to the task to execute after this one, within a
  32. @var{sHT_taskset}. This should not be used outside taskset
  33. internals -- until this comment is changed to the contrary. */
  34. struct sHT_task *next;
  35. };
  36. /** Initialise the task @var{task}.
  37. This cleares its flags, and considers all IO actions to be potentially
  38. possible. @var{task} does not have to be initialised beforehand.
  39. @var{task} may not be concurrently acccessed.
  40. This cannot fail in any way. */
  41. __attribute__((nonnull(1)))
  42. static inline void
  43. sHT_init_task(struct sHT_task *task)
  44. {
  45. *task = (struct sHT_task) {
  46. .epollflags = ~UINT32_C(0),
  47. .flags = 0,
  48. /* TODO: in the Linux kernel, NULL is sometimes actually
  49. mapped and may therefore not be speculatively accessed.
  50. (In userspace, MMAP_PAGE_ZERO, to all zeros).
  51. On x86-64, AMD has promised never to allow mapping a
  52. certain range, use that in this case. */
  53. .next = NULL,
  54. };
  55. }
  56. #endif