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_RUNNING (make_fixnum(1))
22 #define STATE_SUSPENDED (make_fixnum(2))
23 #define STATE_DEAD (make_fixnum(3))
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 * volatile all_threads;
34 extern int dynamic_values_bytes;
36 #ifdef LISP_FEATURE_SB_THREAD
37 #define for_each_thread(th) for(th=all_threads;th;th=th->next)
39 /* there's some possibility a SSC could notice this never actually
41 #define for_each_thread(th) for(th=all_threads;th;th=0)
44 static inline lispobj SymbolValue(u64 tagged_symbol_pointer, void *thread) {
45 struct symbol *sym= (struct symbol *)
46 (pointer_sized_uint_t)(tagged_symbol_pointer-OTHER_POINTER_LOWTAG);
47 #ifdef LISP_FEATURE_SB_THREAD
48 if(thread && sym->tls_index) {
50 ((union per_thread_data *)thread)
51 ->dynamic_values[fixnum_value(sym->tls_index)];
52 if(r!=NO_TLS_VALUE_MARKER_WIDETAG) return r;
57 static inline lispobj SymbolTlValue(u64 tagged_symbol_pointer, void *thread) {
58 struct symbol *sym= (struct symbol *)
59 (pointer_sized_uint_t)(tagged_symbol_pointer-OTHER_POINTER_LOWTAG);
60 #ifdef LISP_FEATURE_SB_THREAD
61 return ((union per_thread_data *)thread)
62 ->dynamic_values[fixnum_value(sym->tls_index)];
68 static inline void SetSymbolValue(u64 tagged_symbol_pointer,lispobj val, void *thread) {
69 struct symbol *sym= (struct symbol *)
70 (pointer_sized_uint_t)(tagged_symbol_pointer-OTHER_POINTER_LOWTAG);
71 #ifdef LISP_FEATURE_SB_THREAD
72 if(thread && sym->tls_index) {
73 lispobj *pr= &(((union per_thread_data *)thread)
74 ->dynamic_values[fixnum_value(sym->tls_index)]);
75 if(*pr!=NO_TLS_VALUE_MARKER_WIDETAG) {
83 static inline void SetTlSymbolValue(u64 tagged_symbol_pointer,lispobj val, void *thread) {
84 #ifdef LISP_FEATURE_SB_THREAD
85 struct symbol *sym= (struct symbol *)
86 (pointer_sized_uint_t)(tagged_symbol_pointer-OTHER_POINTER_LOWTAG);
87 ((union per_thread_data *)thread)
88 ->dynamic_values[fixnum_value(sym->tls_index)]
91 SetSymbolValue(tagged_symbol_pointer,val,thread) ;
95 static inline os_context_t *get_interrupt_context_for_thread(struct thread *th)
97 return th->interrupt_contexts
98 [fixnum_value(SymbolValue(FREE_INTERRUPT_CONTEXT_INDEX,th)-1)];
101 /* This is clearly per-arch and possibly even per-OS code, but we can't
102 * put it somewhere sensible like x86-linux-os.c because it needs too
103 * much stuff like struct thread and all_threads to be defined, which
104 * usually aren't by that time. So, it's here instead. Sorry */
106 static inline struct thread *arch_os_get_current_thread() {
107 #if defined(LISP_FEATURE_SB_THREAD)
108 #if 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)));
115 return pthread_getspecific(specials);
122 #if defined(LISP_FEATURE_SB_THREAD)
123 #define thread_self pthread_self
124 #define thread_kill pthread_kill
125 #define thread_sigmask pthread_sigmask
127 #define thread_self getpid
128 #define thread_kill kill
129 #define thread_sigmask sigprocmask
132 extern void create_initial_thread(lispobj);
134 #endif /* _INCLUDE_THREAD_H_ */