1 #ifndef GC_PTHREAD_SUPPORT_H
2 #define GC_PTHREAD_SUPPORT_H
3 
4 # include "private/gc_priv.h"
5 
6 # if defined(GC_PTHREADS) && !defined(GC_SOLARIS_THREADS) \
7      && !defined(GC_IRIX_THREADS) && !defined(GC_WIN32_THREADS)
8 
9 #if defined(GC_DARWIN_THREADS)
10 # include "private/darwin_stop_world.h"
11 #else
12 # include "private/pthread_stop_world.h"
13 #endif
14 
15 /* We use the allocation lock to protect thread-related data structures. */
16 
17 /* The set of all known threads.  We intercept thread creation and 	*/
18 /* joins.								*/
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.) */
28     pthread_t id;
29     /* Extra bookkeeping information the stopping code uses */
30     struct thread_stop_info stop_info;
31 
32     short flags;
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	*/
42     				/* it.					*/
43     ptr_t stack_end;		/* Cold end of the stack.		*/
44 #   ifdef IA64
45 	ptr_t backing_store_end;
46 	ptr_t backing_store_ptr;
47 #   endif
48     void * status;		/* The value returned from the thread.  */
49     				/* Used only to avoid premature 	*/
50 				/* reclamation of any data it might 	*/
51 				/* reference.				*/
52 #   ifdef THREAD_LOCAL_ALLOC
53 #	if CPP_WORDSZ == 64 && defined(ALIGN_DOUBLE)
54 #	    define GRANULARITY 16
55 #	    define NFREELISTS 49
56 #	else
57 #	    define GRANULARITY 8
58 #	    define NFREELISTS 65
59 #	endif
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];
69 #	endif
70 		/* Free lists contain either a pointer or a small count */
71 		/* reflecting the number of granules allocated at that	*/
72 		/* size.						*/
73 		/* 0 ==> thread-local allocation in use, free list	*/
74 		/*       empty.						*/
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 	*/
83 		/* allocation.						*/
84 #   endif
85 } * GC_thread;
86 
87 # define THREAD_TABLE_SZ 128	/* Must be power of 2	*/
88 extern volatile GC_thread GC_threads[THREAD_TABLE_SZ];
89 
90 extern GC_bool GC_thr_initialized;
91 
92 GC_thread GC_lookup_thread(pthread_t id);
93 
94 void GC_stop_init();
95 
96 #endif /* GC_PTHREADS && !GC_SOLARIS_THREADS.... etc */
97 #endif /* GC_PTHREAD_SUPPORT_H */
98