2 * support for dynamic binding from C
3 * See the "Chapter 9: Specials" of the SBCL Internals Manual.
7 * This software is part of the SBCL system. See the README file for
10 * This software is derived from the CMU CL system, which was
11 * written at Carnegie Mellon University and released into the
12 * public domain. The software is in the public domain and is
13 * provided with absolutely no warranty. See the COPYING and CREDITS
14 * files for more information.
25 #include "pseudo-atomic.h"
26 #include "genesis/symbol.h"
27 #include "genesis/binding.h"
28 #include "genesis/static-symbols.h"
30 void bind_variable(lispobj symbol, lispobj value, void *th)
32 struct binding *binding;
33 struct thread *thread=(struct thread *)th;
34 binding = (struct binding *)get_binding_stack_pointer(thread);
35 set_binding_stack_pointer(thread,binding+1);
36 #ifdef LISP_FEATURE_SB_THREAD
38 struct symbol *sym=(struct symbol *)native_pointer(symbol);
40 lispobj *tls_index_lock=
41 &((struct symbol *)native_pointer(TLS_INDEX_LOCK))->value;
42 FSHOW_SIGNAL((stderr, "entering dynbind tls alloc\n"));
43 set_pseudo_atomic_atomic(thread);
44 get_spinlock(tls_index_lock,(uword_t)th);
46 sym->tls_index=SymbolValue(FREE_TLS_INDEX,0);
47 SetSymbolValue(FREE_TLS_INDEX, sym->tls_index+N_WORD_BYTES, 0);
48 if((sym->tls_index)>=(TLS_SIZE << WORD_SHIFT)) {
49 lose("Thread local storage exhausted.");
52 release_spinlock(tls_index_lock);
53 FSHOW_SIGNAL((stderr, "exiting dynbind tls alloc\n"));
54 clear_pseudo_atomic_atomic(thread);
55 if (get_pseudo_atomic_interrupted(thread))
56 do_pending_interrupt();
58 binding->symbol = sym->tls_index;
59 binding->value = SymbolTlValue(symbol, thread);
62 binding->symbol = symbol;
63 binding->value = SymbolTlValue(symbol, thread);
65 SetTlSymbolValue(symbol, value, thread);
71 struct thread *thread=(struct thread *)th;
72 struct binding *binding;
75 binding = ((struct binding *)get_binding_stack_pointer(thread)) - 1;
77 /* On sb-thread, it's actually a tls-index */
78 symbol = binding->symbol;
80 #ifdef LISP_FEATURE_SB_THREAD
82 ((union per_thread_data *)thread)->dynamic_values[(symbol) >> WORD_SHIFT]
85 SetSymbolValue(symbol, binding->value, thread);
91 set_binding_stack_pointer(thread,binding);
95 unbind_to_here(lispobj *bsp,void *th)
97 struct thread *thread=(struct thread *)th;
98 struct binding *target = (struct binding *)bsp;
99 struct binding *binding = (struct binding *)get_binding_stack_pointer(thread);
102 while (target < binding) {
105 symbol = binding->symbol;
107 if (symbol != UNBOUND_MARKER_WIDETAG) {
108 #ifdef LISP_FEATURE_SB_THREAD
109 ((union per_thread_data *)thread)->dynamic_values[(symbol) >> WORD_SHIFT]
112 SetSymbolValue(symbol, binding->value, thread);
119 set_binding_stack_pointer(thread,binding);