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))
25 #define THREAD_SLOT_OFFSET_WORDS(c) \
26 (offsetof(struct thread,c)/(sizeof (struct thread *)))
28 union per_thread_data {
30 lispobj dynamic_values[1]; /* actually more like 4000 or so */
33 extern struct thread *all_threads;
34 extern int dynamic_values_bytes;
35 extern struct thread *find_thread_by_pid(pid_t pid);
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)
45 static inline lispobj SymbolValue(u32 tagged_symbol_pointer, void *thread) {
46 struct symbol *sym= (struct symbol *)
47 (pointer_sized_uint_t)(tagged_symbol_pointer-OTHER_POINTER_LOWTAG);
48 #ifdef LISP_FEATURE_SB_THREAD
49 if(thread && sym->tls_index) {
51 ((union per_thread_data *)thread)
52 ->dynamic_values[fixnum_value(sym->tls_index)];
53 if(r!=UNBOUND_MARKER_WIDETAG) return r;
58 static inline lispobj SymbolTlValue(u32 tagged_symbol_pointer, void *thread) {
59 struct symbol *sym= (struct symbol *)
60 (pointer_sized_uint_t)(tagged_symbol_pointer-OTHER_POINTER_LOWTAG);
61 #ifdef LISP_FEATURE_SB_THREAD
62 return ((union per_thread_data *)thread)
63 ->dynamic_values[fixnum_value(sym->tls_index)];
69 static inline void SetSymbolValue(u32 tagged_symbol_pointer,lispobj val, void *thread) {
70 struct symbol *sym= (struct symbol *)
71 (pointer_sized_uint_t)(tagged_symbol_pointer-OTHER_POINTER_LOWTAG);
72 #ifdef LISP_FEATURE_SB_THREAD
73 if(thread && sym->tls_index) {
74 lispobj *pr= &(((union per_thread_data *)thread)
75 ->dynamic_values[fixnum_value(sym->tls_index)]);
76 if(*pr!= UNBOUND_MARKER_WIDETAG) {
84 static inline void SetTlSymbolValue(u32 tagged_symbol_pointer,lispobj val, void *thread) {
85 #ifdef LISP_FEATURE_SB_THREAD
86 struct symbol *sym= (struct symbol *)
87 (pointer_sized_uint_t)(tagged_symbol_pointer-OTHER_POINTER_LOWTAG);
88 ((union per_thread_data *)thread)
89 ->dynamic_values[fixnum_value(sym->tls_index)]
92 SetSymbolValue(tagged_symbol_pointer,val,thread) ;
96 static inline os_context_t *get_interrupt_context_for_thread(struct thread *th)
98 return th->interrupt_contexts
99 [fixnum_value(SymbolValue(FREE_INTERRUPT_CONTEXT_INDEX,th)-1)];
102 /* This is clearly per-arch and possibly even per-OS code, but we can't
103 * put it somewhere sensible like x86-linux-os.c because it needs too
104 * much stuff like struct thread and all_threads to be defined, which
105 * usually aren't by that time. So, it's here instead. Sorry */
107 inline static struct thread *arch_os_get_current_thread() {
108 #if defined(LISP_FEATURE_SB_THREAD) && defined (LISP_FEATURE_X86)
109 register struct thread *me=0;
111 __asm__ __volatile__ ("movl %%fs:%c1,%0" : "=r" (me)
112 : "i" (offsetof (struct thread,this)));
120 int arch_os_thread_init(struct thread *thread);
121 extern struct thread *arch_os_get_current_thread();
123 #endif /* _INCLUDE_THREAD_H_ */