0.pre8.33
[sbcl.git] / src / runtime / thread.h
1
2 #if !defined(_INCLUDE_THREAD_H_)
3 #define _INCLUDE_THREAD_H_
4
5 #include <sys/types.h>
6 #include <unistd.h>
7 #include "runtime.h"
8 #include "sbcl.h"
9 #include "os.h"
10 #include "interrupt.h"
11 #ifdef LISP_FEATURE_GENCGC
12 #include "gencgc-alloc-region.h"
13 #else
14 struct alloc_region { };
15 #endif
16 #include "genesis/symbol.h"
17 #include "genesis/static-symbols.h"
18 #include "genesis/thread.h"
19
20 #define THREAD_SLOT_OFFSET_WORDS(c) \
21  (offsetof(struct thread,c)/(sizeof (struct thread *)))
22
23 union per_thread_data {
24     struct thread thread;
25     lispobj dynamic_values[1];  /* actually more like 4000 or so */
26 };
27
28 extern struct thread *all_threads;
29 extern int dynamic_values_bytes;
30 extern struct thread *find_thread_by_pid(pid_t pid);
31
32 #ifdef LISP_FEATURE_SB_THREAD
33 #define for_each_thread(th) for(th=all_threads;th;th=th->next)
34 #else
35 /* there's some possibility a SSC could notice this never actually
36  * loops  */
37 #define for_each_thread(th) for(th=all_threads;th;th=0)
38 #endif
39
40 static inline lispobj SymbolValue(u32 tagged_symbol_pointer, void *thread) {
41     struct symbol *sym= (struct symbol *)
42         (tagged_symbol_pointer-OTHER_POINTER_LOWTAG);
43 #ifdef LISP_FEATURE_SB_THREAD
44     if(thread && sym->tls_index) {
45         lispobj r=
46             ((union per_thread_data *)thread)
47             ->dynamic_values[fixnum_value(sym->tls_index)];
48         if(r!=UNBOUND_MARKER_WIDETAG) return r;
49     }
50 #endif
51     return sym->value;
52 }
53 static inline lispobj SymbolTlValue(u32 tagged_symbol_pointer, void *thread) {
54     struct symbol *sym= (struct symbol *)
55         (tagged_symbol_pointer-OTHER_POINTER_LOWTAG);
56 #ifdef LISP_FEATURE_SB_THREAD
57     return ((union per_thread_data *)thread)
58         ->dynamic_values[fixnum_value(sym->tls_index)];
59 #else
60     return sym->value;
61 #endif
62 }
63
64 static inline void SetSymbolValue(u32 tagged_symbol_pointer,lispobj val, void *thread) {
65     struct symbol *sym= (struct symbol *)
66         (tagged_symbol_pointer-OTHER_POINTER_LOWTAG);
67 #ifdef LISP_FEATURE_SB_THREAD
68     if(thread && sym->tls_index) {
69         lispobj *pr= &(((union per_thread_data *)thread)
70                        ->dynamic_values[fixnum_value(sym->tls_index)]);
71         if(*pr!= UNBOUND_MARKER_WIDETAG) {
72             *pr=val;
73             return;
74         }
75     }
76 #endif
77     sym->value = val;
78 }
79 static inline void SetTlSymbolValue(u32 tagged_symbol_pointer,lispobj val, void *thread) {
80 #ifdef LISP_FEATURE_SB_THREAD
81     struct symbol *sym= (struct symbol *)
82         (tagged_symbol_pointer-OTHER_POINTER_LOWTAG);
83     ((union per_thread_data *)thread)
84         ->dynamic_values[fixnum_value(sym->tls_index)]
85         =val;
86 #else
87     SetSymbolValue(tagged_symbol_pointer,val,thread) ;
88 #endif
89 }
90
91     
92
93 #endif /* _INCLUDE_THREAD_H_ */