Debian Codegraph @

external/bdwgc/include/private/pthread_support.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-2009 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 #ifndef GC_PTHREAD_SUPPORT_H
19 #define GC_PTHREAD_SUPPORT_H
20
21 #include "private/gc_priv.h"
22
23 #if defined(GC_PTHREADS) && !defined(GC_WIN32_THREADS)
24
25 #if defined(GC_DARWIN_THREADS)
26 # include "private/darwin_stop_world.h"
27 #else
28 # include "private/pthread_stop_world.h"
29 #endif
30
31 #ifdef THREAD_LOCAL_ALLOC
32 # include "thread_local_alloc.h"
33 #endif
34
35 #ifdef THREAD_SANITIZER
36 # include "dbg_mlc.h" /* for oh type */
37 #endif
38
39 EXTERN_C_BEGIN
40
41 /* We use the allocation lock to protect thread-related data structures. */
42
43 /* The set of all known threads. We intercept thread creation and */
44 /* joins. */
45 /* Protected by allocation/GC lock. */
46 /* Some of this should be declared volatile, but that's inconsistent */
47 /* with some library routine declarations. */
48 typedef struct GC_Thread_Rep {
49 # ifdef THREAD_SANITIZER
50 char dummy[sizeof(oh)]; /* A dummy field to avoid TSan false */
51 /* positive about the race between */
52 /* GC_has_other_debug_info and */
53 /* GC_suspend_handler_inner (which */
54 /* sets store_stop.stack_ptr). */
55 # endif
56
57 struct GC_Thread_Rep * next; /* More recently allocated threads */
58 /* with a given pthread id come */
59 /* first. (All but the first are */
60 /* guaranteed to be dead, but we may */
61 /* not yet have registered the join.) */
62 pthread_t id;
63 # ifdef USE_TKILL_ON_ANDROID
64 pid_t kernel_id;
65 # endif
66 /* Extra bookkeeping information the stopping code uses */
67 struct thread_stop_info stop_info;
68
69 # if defined(GC_ENABLE_SUSPEND_THREAD) && !defined(GC_DARWIN_THREADS) \
70 && !defined(GC_OPENBSD_UTHREADS) && !defined(NACL)
71 volatile AO_t suspended_ext; /* Thread was suspended externally. */
72 # endif
73
74 unsigned char flags;
75 # define FINISHED 1 /* Thread has exited. */
76 # define DETACHED 2 /* Thread is treated as detached. */
77 /* Thread may really be detached, or */
78 /* it may have been explicitly */
79 /* registered, in which case we can */
80 /* deallocate its GC_Thread_Rep once */
81 /* it unregisters itself, since it */
82 /* may not return a GC pointer. */
83 # define MAIN_THREAD 4 /* True for the original thread only. */
84 # define DISABLED_GC 0x10 /* Collections are disabled while the */
85 /* thread is exiting. */
86
87 unsigned char thread_blocked;
88 /* Protected by GC lock. */
89 /* Treated as a boolean value. If set, */
90 /* thread will acquire GC lock before */
91 /* doing any pointer manipulations, and */
92 /* has set its SP value. Thus it does */
93 /* not need to be sent a signal to stop */
94 /* it. */
95
96 unsigned short finalizer_skipped;
97 unsigned char finalizer_nested;
98 /* Used by GC_check_finalizer_nested() */
99 /* to minimize the level of recursion */
100 /* when a client finalizer allocates */
101 /* memory (initially both are 0). */
102
103 ptr_t stack_end; /* Cold end of the stack (except for */
104 /* main thread). */
105 ptr_t altstack; /* The start of the alt-stack if there */
106 /* is one, NULL otherwise. */
107 word altstack_size; /* The size of the alt-stack if exists. */
108 ptr_t stack; /* The start and size of the normal */
109 /* stack (set by GC_register_altstack). */
110 word stack_size;
111 # if defined(GC_DARWIN_THREADS) && !defined(DARWIN_DONT_PARSE_STACK)
112 ptr_t topOfStack; /* Result of GC_FindTopOfStack(0); */
113 /* valid only if the thread is blocked; */
114 /* non-NULL value means already set. */
115 # endif
116 # ifdef IA64
117 ptr_t backing_store_end;
118 ptr_t backing_store_ptr;
119 # endif
120
121 struct GC_traced_stack_sect_s *traced_stack_sect;
122 /* Points to the "frame" data held in stack by */
123 /* the innermost GC_call_with_gc_active() of */
124 /* this thread. May be NULL. */
125
126 void * status; /* The value returned from the thread. */
127 /* Used only to avoid premature */
128 /* reclamation of any data it might */
129 /* reference. */
130 /* This is unfortunately also the */
131 /* reason we need to intercept join */
132 /* and detach. */
133
134 # ifdef THREAD_LOCAL_ALLOC
135 struct thread_local_freelists tlfs;
136 # endif
137 } * GC_thread;
138
139 #ifndef THREAD_TABLE_SZ
140 # define THREAD_TABLE_SZ 256 /* Power of 2 (for speed). */
141 #endif
142
143 #if CPP_WORDSZ == 64
144 # define THREAD_TABLE_INDEX(id) \
145 (int)(((((NUMERIC_THREAD_ID(id) >> 8) ^ NUMERIC_THREAD_ID(id)) >> 16) \
146 ^ ((NUMERIC_THREAD_ID(id) >> 8) ^ NUMERIC_THREAD_ID(id))) \
147 % THREAD_TABLE_SZ)
148 #else
149 # define THREAD_TABLE_INDEX(id) \
150 (int)(((NUMERIC_THREAD_ID(id) >> 16) \
151 ^ (NUMERIC_THREAD_ID(id) >> 8) \
152 ^ NUMERIC_THREAD_ID(id)) % THREAD_TABLE_SZ)
153 #endif
154
155 GC_EXTERN volatile GC_thread GC_threads[THREAD_TABLE_SZ];
156
157 GC_EXTERN GC_bool GC_thr_initialized;
158
159 GC_INNER GC_thread GC_lookup_thread(pthread_t id);
160
161 GC_EXTERN GC_bool GC_in_thread_creation;
162 /* We may currently be in thread creation or destruction. */
163 /* Only set to TRUE while allocation lock is held. */
164 /* When set, it is OK to run GC from unknown thread. */
165
166 #ifdef NACL
167 GC_EXTERN __thread GC_thread GC_nacl_gc_thread_self;
168 GC_INNER void GC_nacl_initialize_gc_thread(void);
169 GC_INNER void GC_nacl_shutdown_gc_thread(void);
170 #endif
171
172 #ifdef GC_EXPLICIT_SIGNALS_UNBLOCK
173 GC_INNER void GC_unblock_gc_signals(void);
174 #endif
175
176 #ifdef GC_PTHREAD_START_STANDALONE
177 # define GC_INNER_PTHRSTART /* empty */
178 #else
179 # define GC_INNER_PTHRSTART GC_INNER
180 #endif
181
182 GC_INNER_PTHRSTART void * GC_CALLBACK GC_inner_start_routine(
183 struct GC_stack_base *sb, void *arg);
184
185 GC_INNER_PTHRSTART GC_thread GC_start_rtn_prepare_thread(
186 void *(**pstart)(void *),
187 void **pstart_arg,
188 struct GC_stack_base *sb, void *arg);
189 GC_INNER_PTHRSTART void GC_thread_exit_proc(void *);
190
191 EXTERN_C_END
192
193 #endif /* GC_PTHREADS && !GC_WIN32_THREADS */
194
195 #endif /* GC_PTHREAD_SUPPORT_H */