null-threads.c 1.6 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374
  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 License
  5. * as published by the Free Software Foundation; either version 3 of
  6. * the License, or (at your option) any later version.
  7. *
  8. * This library is distributed in the hope that it will be useful, but
  9. * 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
  16. * 02110-1301 USA
  17. */
  18. #ifdef HAVE_CONFIG_H
  19. # include <config.h>
  20. #endif
  21. #include <stdlib.h>
  22. #include "libguile/_scm.h"
  23. #if SCM_USE_NULL_THREADS
  24. #include "libguile/null-threads.h"
  25. static scm_i_pthread_key_t *all_keys = NULL;
  26. static void
  27. destroy_keys (void)
  28. {
  29. scm_i_pthread_key_t *key;
  30. int again;
  31. do {
  32. again = 0;
  33. for (key = all_keys; key; key = key->next)
  34. if (key->value && key->destr_func)
  35. {
  36. void *v = key->value;
  37. key->value = NULL;
  38. key->destr_func (v);
  39. again = 1;
  40. }
  41. } while (again);
  42. }
  43. int
  44. scm_i_pthread_key_create (scm_i_pthread_key_t *key,
  45. void (*destr_func) (void *))
  46. {
  47. if (all_keys == NULL)
  48. atexit (destroy_keys);
  49. key->next = all_keys;
  50. all_keys = key;
  51. key->value = NULL;
  52. key->destr_func = destr_func;
  53. return 0;
  54. }
  55. #endif /* SCM_USE_NULL_THREADS */
  56. /*
  57. Local Variables:
  58. c-file-style: "gnu"
  59. End:
  60. */