null-threads.c 1.6 KB

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