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.
8 * THIS MATERIAL IS PROVIDED AS IS, WITH ABSOLUTELY NO WARRANTY EXPRESSED
9 * OR IMPLIED. ANY USE IS AT YOUR OWN RISK.
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.
18 #ifndef GC_PTHREAD_SUPPORT_H
19 #define GC_PTHREAD_SUPPORT_H
21 # include "private/gc_priv.h"
23 # if defined(GC_PTHREADS) && !defined(GC_WIN32_THREADS)
25 #if defined(GC_DARWIN_THREADS)
26 # include "private/darwin_stop_world.h"
28 # include "private/pthread_stop_world.h"
31 #ifdef THREAD_LOCAL_ALLOC
32 # include "thread_local_alloc.h"
33 #endif /* THREAD_LOCAL_ALLOC */
35 /* We use the allocation lock to protect thread-related data structures. */
37 /* The set of all known threads. We intercept thread creation and */
39 /* Protected by allocation/GC lock. */
40 /* Some of this should be declared volatile, but that's inconsistent */
41 /* with some library routine declarations. */
42 typedef struct GC_Thread_Rep {
43 struct GC_Thread_Rep * next; /* More recently allocated threads */
44 /* with a given pthread id come */
45 /* first. (All but the first are */
46 /* guaranteed to be dead, but we may */
47 /* not yet have registered the join.) */
49 /* Extra bookkeeping information the stopping code uses */
50 struct thread_stop_info stop_info;
53 # define FINISHED 1 /* Thread has exited. */
54 # define DETACHED 2 /* Thread is treated as detached. */
55 /* Thread may really be detached, or */
56 /* it may have have been explicitly */
57 /* registered, in which case we can */
58 /* deallocate its GC_Thread_Rep once */
59 /* it unregisters itself, since it */
60 /* may not return a GC pointer. */
61 # define MAIN_THREAD 4 /* True for the original thread only. */
62 short thread_blocked; /* Protected by GC lock. */
63 /* Treated as a boolean value. If set, */
64 /* thread will acquire GC lock before */
65 /* doing any pointer manipulations, and */
66 /* has set its sp value. Thus it does */
67 /* not need to be sent a signal to stop */
69 ptr_t stack_end; /* Cold end of the stack (except for */
72 ptr_t backing_store_end;
73 ptr_t backing_store_ptr;
76 struct GC_activation_frame_s *activation_frame;
77 /* Points to the "frame" data held in stack by */
78 /* the innermost GC_call_with_gc_active() of */
79 /* this thread. May be NULL. */
81 void * status; /* The value returned from the thread. */
82 /* Used only to avoid premature */
83 /* reclamation of any data it might */
85 /* This is unfortunately also the */
86 /* reason we need to intercept join */
89 unsigned finalizer_nested;
90 unsigned finalizer_skipped; /* Used by GC_check_finalizer_nested() */
91 /* to minimize the level of recursion */
92 /* when a client finalizer allocates */
93 /* memory (initially both are 0). */
95 # ifdef THREAD_LOCAL_ALLOC
96 struct thread_local_freelists tlfs;
100 # define THREAD_TABLE_SZ 256 /* Must be power of 2 */
101 GC_EXTERN volatile GC_thread GC_threads[THREAD_TABLE_SZ];
103 GC_EXTERN GC_bool GC_thr_initialized;
105 GC_INNER GC_thread GC_lookup_thread(pthread_t id);
107 GC_INNER void GC_stop_init(void);
109 GC_EXTERN GC_bool GC_in_thread_creation;
110 /* We may currently be in thread creation or destruction. */
111 /* Only set to TRUE while allocation lock is held. */
112 /* When set, it is OK to run GC from unknown thread. */
114 #endif /* GC_PTHREADS && !GC_SOLARIS_THREADS.... etc */
115 #endif /* GC_PTHREAD_SUPPORT_H */