1 #if !defined(_INCLUDE_THREAD_H_)
2 #define _INCLUDE_THREAD_H_
11 #include "interrupt.h"
12 #ifdef LISP_FEATURE_GENCGC
13 #include "gencgc-alloc-region.h"
15 struct alloc_region
{ };
17 #include "genesis/symbol.h"
18 #include "genesis/static-symbols.h"
19 #include "genesis/thread.h"
21 #define STATE_STARTING (make_fixnum(0))
22 #define STATE_RUNNING (make_fixnum(1))
23 #define STATE_SUSPENDED (make_fixnum(2))
24 #define STATE_DEAD (make_fixnum(3))
26 #define THREAD_SLOT_OFFSET_WORDS(c) \
27 (offsetof(struct thread,c)/(sizeof (struct thread *)))
29 union per_thread_data
{
31 lispobj dynamic_values
[1]; /* actually more like 4000 or so */
34 extern struct thread
* volatile all_threads
;
35 extern int dynamic_values_bytes
;
37 #ifdef LISP_FEATURE_SB_THREAD
38 #define for_each_thread(th) for(th=all_threads;th;th=th->next)
40 /* there's some possibility a SSC could notice this never actually
42 #define for_each_thread(th) for(th=all_threads;th;th=0)
46 SymbolValue(u64 tagged_symbol_pointer
, void *thread
) {
47 struct symbol
*sym
= (struct symbol
*)
48 (pointer_sized_uint_t
)(tagged_symbol_pointer
-OTHER_POINTER_LOWTAG
);
49 #ifdef LISP_FEATURE_SB_THREAD
50 if(thread
&& sym
->tls_index
) {
52 ((union per_thread_data
*)thread
)
53 ->dynamic_values
[fixnum_value(sym
->tls_index
)];
54 if(r
!=NO_TLS_VALUE_MARKER_WIDETAG
) return r
;
61 SymbolTlValue(u64 tagged_symbol_pointer
, void *thread
) {
62 struct symbol
*sym
= (struct symbol
*)
63 (pointer_sized_uint_t
)(tagged_symbol_pointer
-OTHER_POINTER_LOWTAG
);
64 #ifdef LISP_FEATURE_SB_THREAD
65 return ((union per_thread_data
*)thread
)
66 ->dynamic_values
[fixnum_value(sym
->tls_index
)];
73 SetSymbolValue(u64 tagged_symbol_pointer
,lispobj val
, void *thread
) {
74 struct symbol
*sym
= (struct symbol
*)
75 (pointer_sized_uint_t
)(tagged_symbol_pointer
-OTHER_POINTER_LOWTAG
);
76 #ifdef LISP_FEATURE_SB_THREAD
77 if(thread
&& sym
->tls_index
) {
78 lispobj
*pr
= &(((union per_thread_data
*)thread
)
79 ->dynamic_values
[fixnum_value(sym
->tls_index
)]);
80 if(*pr
!=NO_TLS_VALUE_MARKER_WIDETAG
) {
89 SetTlSymbolValue(u64 tagged_symbol_pointer
,lispobj val
, void *thread
) {
90 #ifdef LISP_FEATURE_SB_THREAD
91 struct symbol
*sym
= (struct symbol
*)
92 (pointer_sized_uint_t
)(tagged_symbol_pointer
-OTHER_POINTER_LOWTAG
);
93 ((union per_thread_data
*)thread
)
94 ->dynamic_values
[fixnum_value(sym
->tls_index
)]
97 SetSymbolValue(tagged_symbol_pointer
,val
,thread
) ;
102 os_context_t
*get_interrupt_context_for_thread(struct thread
*th
)
104 return th
->interrupt_contexts
105 [fixnum_value(SymbolValue(FREE_INTERRUPT_CONTEXT_INDEX
,th
)-1)];
108 /* This is clearly per-arch and possibly even per-OS code, but we can't
109 * put it somewhere sensible like x86-linux-os.c because it needs too
110 * much stuff like struct thread and all_threads to be defined, which
111 * usually aren't by that time. So, it's here instead. Sorry */
113 static inline struct thread
*arch_os_get_current_thread() {
114 #if defined(LISP_FEATURE_SB_THREAD)
115 #if defined(LISP_FEATURE_X86)
116 register struct thread
*me
=0;
118 __asm__
__volatile__ ("movl %%fs:%c1,%0" : "=r" (me
)
119 : "i" (offsetof (struct thread
,this)));
122 return pthread_getspecific(specials
);
129 #if defined(LISP_FEATURE_SB_THREAD)
130 #define thread_self pthread_self
131 #define thread_kill pthread_kill
132 #define thread_sigmask pthread_sigmask
133 #define thread_mutex_lock(l) pthread_mutex_lock(l)
134 #define thread_mutex_unlock(l) pthread_mutex_unlock(l)
136 #define thread_self getpid
137 #define thread_kill kill
138 #define thread_sigmask sigprocmask
139 #define thread_mutex_lock(l)
140 #define thread_mutex_unlock(l)
143 extern void create_initial_thread(lispobj
);
145 #endif /* _INCLUDE_THREAD_H_ */