null-threads.c 1.5 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869
  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. #include "libguile/scmconfig.h"
  20. #if SCM_USE_NULL_THREADS
  21. #include "null-threads.h"
  22. static scm_i_pthread_key_t *all_keys = NULL;
  23. static void
  24. destroy_keys (void)
  25. {
  26. scm_i_pthread_key_t *key;
  27. int again;
  28. do {
  29. again = 0;
  30. for (key = all_keys; key; key = key->next)
  31. if (key->value && key->destr_func)
  32. {
  33. void *v = key->value;
  34. key->value = NULL;
  35. key->destr_func (v);
  36. again = 1;
  37. }
  38. } while (again);
  39. }
  40. int
  41. scm_i_pthread_key_create (scm_i_pthread_key_t *key,
  42. void (*destr_func) (void *))
  43. {
  44. if (all_keys == NULL)
  45. atexit (destroy_keys);
  46. key->next = all_keys;
  47. all_keys = key;
  48. key->value = NULL;
  49. key->destr_func = destr_func;
  50. return 0;
  51. }
  52. #endif /* SCM_USE_NULL_THREADS */