2 * support for dynamic binding from C
6 * This software is part of the SBCL system. See the README file for
9 * This software is derived from the CMU CL system, which was
10 * written at Carnegie Mellon University and released into the
11 * public domain. The software is in the public domain and is
12 * provided with absolutely no warranty. See the COPYING and CREDITS
13 * files for more information.
24 #include "pseudo-atomic.h"
25 #include "genesis/symbol.h"
26 #include "genesis/binding.h"
27 #include "genesis/static-symbols.h"
29 void bind_variable(lispobj symbol, lispobj value, void *th)
31 struct binding *binding;
32 struct thread *thread=(struct thread *)th;
33 binding = (struct binding *)get_binding_stack_pointer(thread);
34 set_binding_stack_pointer(thread,binding+1);
35 #ifdef LISP_FEATURE_SB_THREAD
37 struct symbol *sym=(struct symbol *)native_pointer(symbol);
39 lispobj *tls_index_lock=
40 &((struct symbol *)native_pointer(TLS_INDEX_LOCK))->value;
41 FSHOW_SIGNAL((stderr, "entering dynbind tls alloc\n"));
42 set_pseudo_atomic_atomic(thread);
43 get_spinlock(tls_index_lock,(uword_t)th);
45 sym->tls_index=SymbolValue(FREE_TLS_INDEX,0);
46 SetSymbolValue(FREE_TLS_INDEX, sym->tls_index+N_WORD_BYTES, 0);
47 if((sym->tls_index)>=(TLS_SIZE << WORD_SHIFT)) {
48 lose("Thread local storage exhausted.");
51 release_spinlock(tls_index_lock);
52 FSHOW_SIGNAL((stderr, "exiting dynbind tls alloc\n"));
53 clear_pseudo_atomic_atomic(thread);
54 if (get_pseudo_atomic_interrupted(thread))
55 do_pending_interrupt();
59 binding->value = SymbolTlValue(symbol, thread);
60 binding->symbol = symbol;
61 SetTlSymbolValue(symbol, value, thread);
67 struct thread *thread=(struct thread *)th;
68 struct binding *binding;
71 binding = ((struct binding *)get_binding_stack_pointer(thread)) - 1;
73 symbol = binding->symbol;
75 SetTlSymbolValue(symbol, binding->value,thread);
80 set_binding_stack_pointer(thread,binding);
84 unbind_variable(lispobj name, void *th)
86 struct thread *thread=(struct thread *)th;
87 struct binding *binding;
90 binding = ((struct binding *)get_binding_stack_pointer(thread)) - 1;
92 symbol = binding->symbol;
95 lose("unbind_variable, 0x%p != 0x%p", symbol, name);
97 SetTlSymbolValue(symbol, binding->value,thread);
102 set_binding_stack_pointer(thread,binding);
106 unbind_to_here(lispobj *bsp,void *th)
108 struct thread *thread=(struct thread *)th;
109 struct binding *target = (struct binding *)bsp;
110 struct binding *binding = (struct binding *)get_binding_stack_pointer(thread);
113 while (target < binding) {
116 symbol = binding->symbol;
118 if (symbol != UNBOUND_MARKER_WIDETAG) {
119 SetTlSymbolValue(symbol, binding->value,thread);
125 set_binding_stack_pointer(thread,binding);