2 #if !defined(_INCLUDE_THREAD_H_)
3 #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_RUNNING (make_fixnum(0))
22 #define STATE_STOPPING (make_fixnum(1))
23 #define STATE_STOPPED (make_fixnum(2))
24 #define STATE_DEAD (make_fixnum(3))
25 #define STATE_STARTING (make_fixnum(4))
27 #define THREAD_SLOT_OFFSET_WORDS(c) \
28 (offsetof(struct thread,c)/(sizeof (struct thread *)))
30 union per_thread_data
{
32 lispobj dynamic_values
[1]; /* actually more like 4000 or so */
35 extern struct thread
*all_threads
;
36 extern int dynamic_values_bytes
;
37 extern struct thread
*find_thread_by_os_thread(os_thread_t tid
);
39 #ifdef LISP_FEATURE_SB_THREAD
40 #define for_each_thread(th) for(th=all_threads;th;th=th->next)
42 /* there's some possibility a SSC could notice this never actually
44 #define for_each_thread(th) for(th=all_threads;th;th=0)
47 static inline lispobj
SymbolValue(u64 tagged_symbol_pointer
, void *thread
) {
48 struct symbol
*sym
= (struct symbol
*)
49 (pointer_sized_uint_t
)(tagged_symbol_pointer
-OTHER_POINTER_LOWTAG
);
50 #ifdef LISP_FEATURE_SB_THREAD
51 if(thread
&& sym
->tls_index
) {
53 ((union per_thread_data
*)thread
)
54 ->dynamic_values
[fixnum_value(sym
->tls_index
)];
55 if(r
!=UNBOUND_MARKER_WIDETAG
) return r
;
60 static inline lispobj
SymbolTlValue(u64 tagged_symbol_pointer
, void *thread
) {
61 struct symbol
*sym
= (struct symbol
*)
62 (pointer_sized_uint_t
)(tagged_symbol_pointer
-OTHER_POINTER_LOWTAG
);
63 #ifdef LISP_FEATURE_SB_THREAD
64 return ((union per_thread_data
*)thread
)
65 ->dynamic_values
[fixnum_value(sym
->tls_index
)];
71 static inline void SetSymbolValue(u64 tagged_symbol_pointer
,lispobj val
, void *thread
) {
72 struct symbol
*sym
= (struct symbol
*)
73 (pointer_sized_uint_t
)(tagged_symbol_pointer
-OTHER_POINTER_LOWTAG
);
74 #ifdef LISP_FEATURE_SB_THREAD
75 if(thread
&& sym
->tls_index
) {
76 lispobj
*pr
= &(((union per_thread_data
*)thread
)
77 ->dynamic_values
[fixnum_value(sym
->tls_index
)]);
78 if(*pr
!= UNBOUND_MARKER_WIDETAG
) {
86 static inline void SetTlSymbolValue(u64 tagged_symbol_pointer
,lispobj val
, void *thread
) {
87 #ifdef LISP_FEATURE_SB_THREAD
88 struct symbol
*sym
= (struct symbol
*)
89 (pointer_sized_uint_t
)(tagged_symbol_pointer
-OTHER_POINTER_LOWTAG
);
90 ((union per_thread_data
*)thread
)
91 ->dynamic_values
[fixnum_value(sym
->tls_index
)]
94 SetSymbolValue(tagged_symbol_pointer
,val
,thread
) ;
98 static inline os_context_t
*get_interrupt_context_for_thread(struct thread
*th
)
100 return th
->interrupt_contexts
101 [fixnum_value(SymbolValue(FREE_INTERRUPT_CONTEXT_INDEX
,th
)-1)];
104 /* This is clearly per-arch and possibly even per-OS code, but we can't
105 * put it somewhere sensible like x86-linux-os.c because it needs too
106 * much stuff like struct thread and all_threads to be defined, which
107 * usually aren't by that time. So, it's here instead. Sorry */
109 static inline struct thread
*arch_os_get_current_thread() {
110 #if defined(LISP_FEATURE_SB_THREAD)
111 #if defined(LISP_FEATURE_X86)
112 register struct thread
*me
=0;
114 __asm__
__volatile__ ("movl %%fs:%c1,%0" : "=r" (me
)
115 : "i" (offsetof (struct thread
,this)));
118 return pthread_getspecific(specials
);
125 #if defined(LISP_FEATURE_SB_THREAD)
126 #define thread_self pthread_self
127 #define thread_kill pthread_kill
128 #define thread_sigmask pthread_sigmask
130 #define thread_self getpid
131 #define thread_kill kill
132 #define thread_sigmask sigprocmask
135 extern void create_initial_thread(lispobj
);
137 #endif /* _INCLUDE_THREAD_H_ */