Debian Codegraph @

gc/include/gc_pthread_redirects.h

raw
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
18 /* Our pthread support normally needs to intercept a number of thread */
19 /* calls. We arrange to do that here, if appropriate. */
20
21 #ifndef GC_PTHREAD_REDIRECTS_H
22 #define GC_PTHREAD_REDIRECTS_H
23
24 /* Included from gc.h only. Included only if GC_PTHREADS. */
25 #if defined(GC_H) && defined(GC_PTHREADS)
26
27 /* We need to intercept calls to many of the threads primitives, so */
28 /* that we can locate thread stacks and stop the world. */
29 /* Note also that the collector cannot always see thread specific data. */
30 /* Thread specific data should generally consist of pointers to */
31 /* uncollectible objects (allocated with GC_malloc_uncollectable, */
32 /* not the system malloc), which are deallocated using the destructor */
33 /* facility in thr_keycreate. Alternatively, keep a redundant pointer */
34 /* to thread specific data on the thread stack. */
35
36 #ifndef GC_PTHREAD_REDIRECTS_ONLY
37
38 # include <pthread.h>
39 # ifndef GC_NO_DLOPEN
40 # include <dlfcn.h>
41 # endif
42 # ifndef GC_NO_PTHREAD_SIGMASK
43 # include <signal.h> /* needed anyway for proper redirection */
44 # endif
45
46 # ifdef __cplusplus
47 extern "C" {
48 # endif
49
50 # ifndef GC_SUSPEND_THREAD_ID
51 # define GC_SUSPEND_THREAD_ID pthread_t
52 # endif
53
54 # ifndef GC_NO_DLOPEN
55 GC_API void *GC_dlopen(const char * /* path */, int /* mode */);
56 # endif /* !GC_NO_DLOPEN */
57
58 # ifndef GC_NO_PTHREAD_SIGMASK
59 # if defined(GC_PTHREAD_SIGMASK_NEEDED) || defined(_BSD_SOURCE) \
60 || defined(_GNU_SOURCE) || defined(_NETBSD_SOURCE) \
61 || (_POSIX_C_SOURCE >= 199506L) || (_XOPEN_SOURCE >= 500) \
62 || (__POSIX_VISIBLE >= 199506) /* xBSD internal macro */
63 GC_API int GC_pthread_sigmask(int /* how */, const sigset_t *,
64 sigset_t * /* oset */);
65 # else
66 # define GC_NO_PTHREAD_SIGMASK
67 # endif
68 # endif /* !GC_NO_PTHREAD_SIGMASK */
69
70 # ifndef GC_PTHREAD_CREATE_CONST
71 /* This is used for pthread_create() only. */
72 # define GC_PTHREAD_CREATE_CONST const
73 # endif
74
75 GC_API int GC_pthread_create(pthread_t *,
76 GC_PTHREAD_CREATE_CONST pthread_attr_t *,
77 void *(*)(void *), void * /* arg */);
78 GC_API int GC_pthread_join(pthread_t, void ** /* retval */);
79 GC_API int GC_pthread_detach(pthread_t);
80
81 # ifndef GC_NO_PTHREAD_CANCEL
82 GC_API int GC_pthread_cancel(pthread_t);
83 # endif
84
85 # if defined(GC_HAVE_PTHREAD_EXIT) && !defined(GC_PTHREAD_EXIT_DECLARED)
86 # define GC_PTHREAD_EXIT_DECLARED
87 GC_API void GC_pthread_exit(void *) GC_PTHREAD_EXIT_ATTRIBUTE;
88 # endif
89
90 # ifdef __cplusplus
91 } /* extern "C" */
92 # endif
93
94 #endif /* !GC_PTHREAD_REDIRECTS_ONLY */
95
96 #if !defined(GC_NO_THREAD_REDIRECTS) && !defined(GC_USE_LD_WRAP)
97 /* Unless the compiler supports #pragma extern_prefix, the Tru64 */
98 /* UNIX <pthread.h> redefines some POSIX thread functions to use */
99 /* mangled names. Anyway, it's safe to undef them before redefining. */
100 # undef pthread_create
101 # undef pthread_join
102 # undef pthread_detach
103 # define pthread_create GC_pthread_create
104 # define pthread_join GC_pthread_join
105 # define pthread_detach GC_pthread_detach
106
107 # ifndef GC_NO_PTHREAD_SIGMASK
108 # undef pthread_sigmask
109 # define pthread_sigmask GC_pthread_sigmask
110 # endif
111 # ifndef GC_NO_DLOPEN
112 # undef dlopen
113 # define dlopen GC_dlopen
114 # endif
115 # ifndef GC_NO_PTHREAD_CANCEL
116 # undef pthread_cancel
117 # define pthread_cancel GC_pthread_cancel
118 # endif
119 # ifdef GC_HAVE_PTHREAD_EXIT
120 # undef pthread_exit
121 # define pthread_exit GC_pthread_exit
122 # endif
123 #endif /* !GC_NO_THREAD_REDIRECTS */
124
125 #endif /* GC_PTHREADS */
126
127 #endif /* GC_PTHREAD_REDIRECTS_H */