674f051595895f71ac198fef940545de7b0bf3a4
[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 #error "threading doesn't work with cheney gc yet"
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 #define for_each_thread(th) for(th=all_threads;th;th=th->next)
33
34 static inline lispobj SymbolValue(u32 tagged_symbol_pointer, void *thread) {
35     struct symbol *sym= (struct symbol *)
36         (tagged_symbol_pointer-OTHER_POINTER_LOWTAG);
37     if(thread && sym->tls_index) {
38         lispobj r=
39             ((union per_thread_data *)thread)
40             ->dynamic_values[fixnum_value(sym->tls_index)];
41         if(r!=UNBOUND_MARKER_WIDETAG) return r;
42     }
43     return sym->value;
44 }
45 static inline lispobj SymbolTlValue(u32 tagged_symbol_pointer, void *thread) {
46     struct symbol *sym= (struct symbol *)
47         (tagged_symbol_pointer-OTHER_POINTER_LOWTAG);
48     return ((union per_thread_data *)thread)
49         ->dynamic_values[fixnum_value(sym->tls_index)];
50 }
51
52 static inline void SetSymbolValue(u32 tagged_symbol_pointer,lispobj val, void *thread) {
53     struct symbol *sym= (struct symbol *)
54         (tagged_symbol_pointer-OTHER_POINTER_LOWTAG);
55     if(thread && sym->tls_index) {
56         lispobj *pr= &(((union per_thread_data *)thread)
57                        ->dynamic_values[fixnum_value(sym->tls_index)]);
58         if(*pr!= UNBOUND_MARKER_WIDETAG) {
59             *pr=val;
60             return;
61         }
62     }
63     sym->value = val;
64 }
65 static inline void SetTlSymbolValue(u32 tagged_symbol_pointer,lispobj val, void *thread) {
66     struct symbol *sym= (struct symbol *)
67         (tagged_symbol_pointer-OTHER_POINTER_LOWTAG);
68     ((union per_thread_data *)thread)
69         ->dynamic_values[fixnum_value(sym->tls_index)]
70         =val;
71 }
72
73     
74
75 #endif /* _INCLUDE_THREAD_H_ */