boehm-gc: revert all CACAO-specific modifications; this is now an exact copy of the...
[cacao.git] / src / mm / boehm-gc / include / private / pthread_support.h
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_WIN32_THREADS)
7      
8 #if defined(GC_DARWIN_THREADS)
9 # include "private/darwin_stop_world.h"
10 #else
11 # include "private/pthread_stop_world.h"
12 #endif
13
14 #ifdef THREAD_LOCAL_ALLOC
15 # include "thread_local_alloc.h"
16 #endif /* THREAD_LOCAL_ALLOC */
17
18 /* We use the allocation lock to protect thread-related data structures. */
19
20 /* The set of all known threads.  We intercept thread creation and      */
21 /* joins.                                                               */
22 /* Protected by allocation/GC lock.                                     */
23 /* Some of this should be declared volatile, but that's inconsistent    */
24 /* with some library routine declarations.                              */
25 typedef struct GC_Thread_Rep {
26     struct GC_Thread_Rep * next;  /* More recently allocated threads    */
27                                   /* with a given pthread id come       */
28                                   /* first.  (All but the first are     */
29                                   /* guaranteed to be dead, but we may  */
30                                   /* not yet have registered the join.) */
31     pthread_t id;
32     /* Extra bookkeeping information the stopping code uses */
33     struct thread_stop_info stop_info;
34     
35     short flags;
36 #       define FINISHED 1       /* Thread has exited.   */
37 #       define DETACHED 2       /* Thread is treated as detached.       */
38                                 /* Thread may really be detached, or    */
39                                 /* it may have have been explicitly     */
40                                 /* registered, in which case we can     */
41                                 /* deallocate its GC_Thread_Rep once    */
42                                 /* it unregisters itself, since it      */
43                                 /* may not return a GC pointer.         */
44 #       define MAIN_THREAD 4    /* True for the original thread only.   */
45     short thread_blocked;       /* Protected by GC lock.                */
46                                 /* Treated as a boolean value.  If set, */
47                                 /* thread will acquire GC lock before   */
48                                 /* doing any pointer manipulations, and */
49                                 /* has set its sp value.  Thus it does  */
50                                 /* not need to be sent a signal to stop */
51                                 /* it.                                  */
52     ptr_t stack_end;            /* Cold end of the stack (except for    */
53                                 /* main thread).                        */
54 #   ifdef IA64
55         ptr_t backing_store_end;
56         ptr_t backing_store_ptr;
57 #   endif
58     void * status;              /* The value returned from the thread.  */
59                                 /* Used only to avoid premature         */
60                                 /* reclamation of any data it might     */
61                                 /* reference.                           */
62                                 /* This is unfortunately also the       */
63                                 /* reason we need to intercept join     */
64                                 /* and detach.                          */
65 #   ifdef THREAD_LOCAL_ALLOC
66         struct thread_local_freelists tlfs;
67 #   endif
68 } * GC_thread;
69
70 # define THREAD_TABLE_SZ 256    /* Must be power of 2   */
71 extern volatile GC_thread GC_threads[THREAD_TABLE_SZ];
72
73 extern GC_bool GC_thr_initialized;
74
75 GC_thread GC_lookup_thread(pthread_t id);
76
77 void GC_stop_init(void);
78
79 extern GC_bool GC_in_thread_creation;
80         /* We may currently be in thread creation or destruction.       */
81         /* Only set to TRUE while allocation lock is held.              */
82         /* When set, it is OK to run GC from unknown thread.            */
83
84 #endif /* GC_PTHREADS && !GC_SOLARIS_THREADS.... etc */
85 #endif /* GC_PTHREAD_SUPPORT_H */