task.h 1.5 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253
  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 <stdint.h>
  16. struct sHT_object_cache;
  17. #define sHT_TASK_SCHEDULED UINT32_C(1)
  18. /** Something to do that may block. If it would block, another task is run
  19. instead. It is automatically resumed. */
  20. struct sHT_task {
  21. /** Indicates which IO actions might be possible */
  22. uint32_t epollflags;
  23. /** @code{sHT_TASK_SCHEDULED}: this task is on a queue of things to
  24. do. */
  25. uint32_t flags;
  26. };
  27. /** Initialise the task @var{task}.
  28. This cleares its flags, and considers all IO actions to be potentially
  29. possible.
  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->epollflags = ~UINT32_C(0);
  37. task->flags = 0;
  38. }
  39. #endif