gc_pthread_redirects.h 3.7 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102
  1. /*
  2. * Copyright (c) 1994 by Xerox Corporation. All rights reserved.
  3. * Copyright (c) 1996 by Silicon Graphics. All rights reserved.
  4. * Copyright (c) 1998 by Fergus Henderson. All rights reserved.
  5. * Copyright (c) 2000-2010 by Hewlett-Packard Development Company.
  6. * All rights reserved.
  7. *
  8. * THIS MATERIAL IS PROVIDED AS IS, WITH ABSOLUTELY NO WARRANTY EXPRESSED
  9. * OR IMPLIED. ANY USE IS AT YOUR OWN RISK.
  10. *
  11. * Permission is hereby granted to use or copy this program
  12. * for any purpose, provided the above notices are retained on all copies.
  13. * Permission to modify the code and to distribute modified code is granted,
  14. * provided the above notices are retained, and a notice that the code was
  15. * modified is included with the above copyright notice.
  16. */
  17. /* Our pthread support normally needs to intercept a number of thread */
  18. /* calls. We arrange to do that here, if appropriate. */
  19. /* Included from gc.h only. Included only if GC_PTHREADS. */
  20. #if defined(GC_H) && defined(GC_PTHREADS)
  21. /* We need to intercept calls to many of the threads primitives, so */
  22. /* that we can locate thread stacks and stop the world. */
  23. /* Note also that the collector cannot always see thread specific data. */
  24. /* Thread specific data should generally consist of pointers to */
  25. /* uncollectible objects (allocated with GC_malloc_uncollectable, */
  26. /* not the system malloc), which are deallocated using the destructor */
  27. /* facility in thr_keycreate. Alternatively, keep a redundant pointer */
  28. /* to thread specific data on the thread stack. */
  29. #ifndef GC_PTHREAD_REDIRECTS_ONLY
  30. # include <pthread.h>
  31. # ifndef GC_SUSPEND_THREAD_ID
  32. # define GC_SUSPEND_THREAD_ID pthread_t
  33. # endif
  34. # ifndef GC_NO_DLOPEN
  35. # include <dlfcn.h>
  36. GC_API void *GC_dlopen(const char * /* path */, int /* mode */);
  37. # endif /* !GC_NO_DLOPEN */
  38. # ifndef GC_NO_PTHREAD_SIGMASK
  39. # include <signal.h>
  40. GC_API int GC_pthread_sigmask(int /* how */, const sigset_t *,
  41. sigset_t * /* oset */);
  42. # endif /* !GC_NO_PTHREAD_SIGMASK */
  43. # ifndef GC_PTHREAD_CREATE_CONST
  44. /* This is used for pthread_create() only. */
  45. # define GC_PTHREAD_CREATE_CONST const
  46. # endif
  47. GC_API int GC_pthread_create(pthread_t *,
  48. GC_PTHREAD_CREATE_CONST pthread_attr_t *,
  49. void *(*)(void *), void * /* arg */);
  50. GC_API int GC_pthread_join(pthread_t, void ** /* retval */);
  51. GC_API int GC_pthread_detach(pthread_t);
  52. # ifndef GC_NO_PTHREAD_CANCEL
  53. GC_API int GC_pthread_cancel(pthread_t);
  54. # endif
  55. # if defined(GC_PTHREAD_EXIT_ATTRIBUTE) && !defined(GC_PTHREAD_EXIT_DECLARED)
  56. # define GC_PTHREAD_EXIT_DECLARED
  57. GC_API void GC_pthread_exit(void *) GC_PTHREAD_EXIT_ATTRIBUTE;
  58. # endif
  59. #endif /* !GC_PTHREAD_REDIRECTS_ONLY */
  60. #if !defined(GC_NO_THREAD_REDIRECTS) && !defined(GC_USE_LD_WRAP)
  61. /* Unless the compiler supports #pragma extern_prefix, the Tru64 */
  62. /* UNIX <pthread.h> redefines some POSIX thread functions to use */
  63. /* mangled names. Anyway, it's safe to undef them before redefining. */
  64. # undef pthread_create
  65. # undef pthread_join
  66. # undef pthread_detach
  67. # define pthread_create GC_pthread_create
  68. # define pthread_join GC_pthread_join
  69. # define pthread_detach GC_pthread_detach
  70. # ifndef GC_NO_PTHREAD_SIGMASK
  71. # undef pthread_sigmask
  72. # define pthread_sigmask GC_pthread_sigmask
  73. # endif
  74. # ifndef GC_NO_DLOPEN
  75. # undef dlopen
  76. # define dlopen GC_dlopen
  77. # endif
  78. # ifndef GC_NO_PTHREAD_CANCEL
  79. # undef pthread_cancel
  80. # define pthread_cancel GC_pthread_cancel
  81. # endif
  82. # ifdef GC_PTHREAD_EXIT_ATTRIBUTE
  83. # undef pthread_exit
  84. # define pthread_exit GC_pthread_exit
  85. # endif
  86. #endif /* !GC_NO_THREAD_REDIRECTS */
  87. #endif /* GC_PTHREADS */