coop-pthreads.h 2.3 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182
  1. /* classes: h_files */
  2. #ifndef SCM_COOP_PTHREADS_H
  3. #define SCM_COOP_PTHREADS_H
  4. /* Copyright (C) 2002, 2006 Free Software Foundation, Inc.
  5. *
  6. * This library is free software; you can redistribute it and/or
  7. * modify it under the terms of the GNU Lesser General Public
  8. * License as published by the Free Software Foundation; either
  9. * version 2.1 of the License, or (at your option) any later version.
  10. *
  11. * This library is distributed in the hope that it will be useful,
  12. * but WITHOUT ANY WARRANTY; without even the implied warranty of
  13. * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
  14. * Lesser General Public License for more details.
  15. *
  16. * You should have received a copy of the GNU Lesser General Public
  17. * License along with this library; if not, write to the Free Software
  18. * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
  19. */
  20. /* The coop-pthreads implementation. We use pthreads for the basic
  21. multi threading stuff, but rig it so that only one thread is ever
  22. active inside Guile.
  23. */
  24. #include <pthread.h>
  25. #include "libguile/iselect.h"
  26. #if (SCM_ENABLE_DEPRECATED == 1)
  27. /* Thread local data support --- generic C API */
  28. typedef pthread_key_t scm_t_key;
  29. #define scm_key_create pthread_key_create
  30. #define scm_setspecific pthread_setspecific
  31. #define scm_getspecific pthread_getspecific
  32. #define scm_key_delete pthread_key_delete
  33. #endif /* SCM_ENABLE_DEPRECATED == 1 */
  34. /* Since only one thread can be active anyway, we don't need to do
  35. anything special around critical sections. In fact, that's the
  36. reason we do only support cooperative threading: Guile's critical
  37. regions have not been completely identified yet. (I think.) */
  38. #define SCM_CRITICAL_SECTION_START
  39. #define SCM_CRITICAL_SECTION_END
  40. #define SCM_I_THREAD_SWITCH_COUNT 50
  41. #define SCM_THREAD_SWITCHING_CODE \
  42. do { \
  43. scm_i_switch_counter--; \
  44. if (scm_i_switch_counter == 0) \
  45. { \
  46. scm_i_switch_counter = SCM_I_THREAD_SWITCH_COUNT; \
  47. scm_yield(); \
  48. } \
  49. } while (0)
  50. SCM_API int scm_i_switch_counter;
  51. #define SCM_THREAD_LOCAL_DATA (scm_i_copt_thread_data)
  52. #define SCM_SET_THREAD_LOCAL_DATA(ptr) (scm_i_copt_set_thread_data (ptr))
  53. SCM_API void *scm_i_copt_thread_data;
  54. SCM_API void scm_i_copt_set_thread_data (void *data);
  55. #endif /* SCM_COOP_PTHREAD_H */
  56. /*
  57. Local Variables:
  58. c-file-style: "gnu"
  59. End:
  60. */