alloc.c 751 B

1234567891011121314151617181920212223242526272829303132
  1. // SPDX-License-Identifier: GPL-2.0 or GPL-3.0
  2. // Copyright © 2018-2019 Ariadne Devos
  3. /* shttpd - allocate task structures */
  4. #include "worker.h"
  5. #include <sHT/compiler.h>
  6. #include <sHT/nospec.h>
  7. #include <sHT/test.h>
  8. #include <stddef.h>
  9. #include <string.h>
  10. /* struct sHT_paper_mill is a stack structure. */
  11. sHT_paper
  12. sHT_alloc_paper(struct sHT_paper_mill *mill)
  13. {
  14. /* sHT_paper_mill is a stack structure */
  15. if (sHT_zero_p(mill->length))
  16. return NULL;
  17. return mill->first[sHT_index_nospec(--(mill->length), mill->capacity)];
  18. }
  19. void
  20. sHT_free_paper(struct sHT_paper_mill *mill, sHT_paper p)
  21. {
  22. /* From docstring: p must come from mill.
  23. Double-freeing is not allowed. */
  24. mill->first[sHT_index_nospec(mill->length++, mill->capacity)] = p;
  25. }