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/thread.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,(long)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();
60 binding->value = SymbolTlValue(symbol, thread);
61 binding->symbol = symbol;
62 SetTlSymbolValue(symbol, value, thread);
68 struct thread *thread=(struct thread *)th;
69 struct binding *binding;
72 binding = ((struct binding *)get_binding_stack_pointer(thread)) - 1;
74 symbol = binding->symbol;
76 SetTlSymbolValue(symbol, binding->value,thread);
81 set_binding_stack_pointer(thread,binding);
85 unbind_to_here(lispobj *bsp,void *th)
87 struct thread *thread=(struct thread *)th;
88 struct binding *target = (struct binding *)bsp;
89 struct binding *binding = (struct binding *)get_binding_stack_pointer(thread);
92 while (target < binding) {
95 symbol = binding->symbol;
97 if (symbol != UNBOUND_MARKER_WIDETAG) {
98 SetTlSymbolValue(symbol, binding->value,thread);
104 set_binding_stack_pointer(thread,binding);