1 #ifndef GC_PTHREAD_SUPPORT_H
2 #define GC_PTHREAD_SUPPORT_H
4 # include "private/gc_priv.h"
6 # if defined(GC_PTHREADS) && !defined(GC_SOLARIS_THREADS) \
7 && !defined(GC_IRIX_THREADS) && !defined(GC_WIN32_THREADS)
9 #if defined(GC_DARWIN_THREADS)
10 # include "private/darwin_stop_world.h"
12 # include "private/pthread_stop_world.h"
15 /* We use the allocation lock to protect thread-related data structures. */
17 /* The set of all known threads. We intercept thread creation and */
19 /* Protected by allocation/GC lock. */
20 /* Some of this should be declared volatile, but that's inconsistent */
21 /* with some library routine declarations. */
22 typedef struct GC_Thread_Rep
{
23 struct GC_Thread_Rep
* next
; /* More recently allocated threads */
24 /* with a given pthread id come */
25 /* first. (All but the first are */
26 /* guaranteed to be dead, but we may */
27 /* not yet have registered the join.) */
29 /* Extra bookkeeping information the stopping code uses */
30 struct thread_stop_info stop_info
;
33 # define FINISHED 1 /* Thread has exited. */
34 # define DETACHED 2 /* Thread is intended to be detached. */
35 # define MAIN_THREAD 4 /* True for the original thread only. */
36 short thread_blocked
; /* Protected by GC lock. */
37 /* Treated as a boolean value. If set, */
38 /* thread will acquire GC lock before */
39 /* doing any pointer manipulations, and */
40 /* has set its sp value. Thus it does */
41 /* not need to be sent a signal to stop */
43 ptr_t stack_end
; /* Cold end of the stack. */
45 ptr_t backing_store_end
;
46 ptr_t backing_store_ptr
;
48 void * status
; /* The value returned from the thread. */
49 /* Used only to avoid premature */
50 /* reclamation of any data it might */
52 # ifdef THREAD_LOCAL_ALLOC
53 # if CPP_WORDSZ == 64 && defined(ALIGN_DOUBLE)
54 # define GRANULARITY 16
55 # define NFREELISTS 49
57 # define GRANULARITY 8
58 # define NFREELISTS 65
60 /* The ith free list corresponds to size i*GRANULARITY */
61 # define INDEX_FROM_BYTES(n) ((ADD_SLOP(n) + GRANULARITY - 1)/GRANULARITY)
62 # define BYTES_FROM_INDEX(i) ((i) * GRANULARITY - EXTRA_BYTES)
63 # define SMALL_ENOUGH(bytes) (ADD_SLOP(bytes) <= \
64 (NFREELISTS-1)*GRANULARITY)
65 ptr_t ptrfree_freelists
[NFREELISTS
];
66 ptr_t normal_freelists
[NFREELISTS
];
67 # ifdef GC_GCJ_SUPPORT
68 ptr_t gcj_freelists
[NFREELISTS
];
70 /* Free lists contain either a pointer or a small count */
71 /* reflecting the number of granules allocated at that */
73 /* 0 ==> thread-local allocation in use, free list */
75 /* > 0, <= DIRECT_GRANULES ==> Using global allocation, */
76 /* too few objects of this size have been */
77 /* allocated by this thread. */
78 /* >= HBLKSIZE => pointer to nonempty free list. */
79 /* > DIRECT_GRANULES, < HBLKSIZE ==> transition to */
80 /* local alloc, equivalent to 0. */
81 # define DIRECT_GRANULES (HBLKSIZE/GRANULARITY)
82 /* Don't use local free lists for up to this much */
87 # define THREAD_TABLE_SZ 128 /* Must be power of 2 */
88 extern volatile GC_thread GC_threads
[THREAD_TABLE_SZ
];
90 extern GC_bool GC_thr_initialized
;
92 GC_thread
GC_lookup_thread(pthread_t id
);
96 extern GC_bool GC_in_thread_creation
;
97 /* We may currently be in thread creation or destruction. */
98 /* Only set to TRUE while allocation lock is held. */
99 /* When set, it is OK to run GC from unknown thread. */
101 #endif /* GC_PTHREADS && !GC_SOLARIS_THREADS.... etc */
102 #endif /* GC_PTHREAD_SUPPORT_H */