null-threads.c 1.5 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667
  1. /* Copyright 2002,2006,2008,2018
  2. Free Software Foundation, Inc.
  3. This file is part of Guile.
  4. Guile is free software: you can redistribute it and/or modify it
  5. under the terms of the GNU Lesser General Public License as published
  6. by the Free Software Foundation, either version 3 of the License, or
  7. (at your option) any later version.
  8. Guile is distributed in the hope that it will be useful, but WITHOUT
  9. ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
  10. FITNESS FOR A PARTICULAR PURPOSE. See the GNU Lesser General Public
  11. License for more details.
  12. You should have received a copy of the GNU Lesser General Public
  13. License along with Guile. If not, see
  14. <https://www.gnu.org/licenses/>. */
  15. #ifdef HAVE_CONFIG_H
  16. # include <config.h>
  17. #endif
  18. #include <stdlib.h>
  19. #if SCM_USE_NULL_THREADS
  20. #include "null-threads.h"
  21. static scm_i_pthread_key_t *all_keys = NULL;
  22. static void
  23. destroy_keys (void)
  24. {
  25. scm_i_pthread_key_t *key;
  26. int again;
  27. do {
  28. again = 0;
  29. for (key = all_keys; key; key = key->next)
  30. if (key->value && key->destr_func)
  31. {
  32. void *v = key->value;
  33. key->value = NULL;
  34. key->destr_func (v);
  35. again = 1;
  36. }
  37. } while (again);
  38. }
  39. int
  40. scm_i_pthread_key_create (scm_i_pthread_key_t *key,
  41. void (*destr_func) (void *))
  42. {
  43. if (all_keys == NULL)
  44. atexit (destroy_keys);
  45. key->next = all_keys;
  46. all_keys = key;
  47. key->value = NULL;
  48. key->destr_func = destr_func;
  49. return 0;
  50. }
  51. #endif /* SCM_USE_NULL_THREADS */