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 #if defined(BINDING_STACK_POINTER)
31 #define GetBSP() ((struct binding *)SymbolValue(BINDING_STACK_POINTER,thread))
32 #define SetBSP(value) SetSymbolValue(BINDING_STACK_POINTER, (lispobj)(value),thread)
34 #define GetBSP() ((struct binding *)current_binding_stack_pointer)
35 #define SetBSP(value) (current_binding_stack_pointer=(lispobj *)(value))
38 void bind_variable(lispobj symbol, lispobj value, void *th)
40 struct binding *binding;
41 struct thread *thread=(struct thread *)th;
44 #ifdef LISP_FEATURE_SB_THREAD
46 struct symbol *sym=(struct symbol *)native_pointer(symbol);
48 lispobj *tls_index_lock=
49 &((struct symbol *)native_pointer(TLS_INDEX_LOCK))->value;
50 FSHOW_SIGNAL((stderr, "entering dynbind tls alloc\n"));
51 set_pseudo_atomic_atomic(th);
52 get_spinlock(tls_index_lock,(long)th);
54 sym->tls_index=SymbolValue(FREE_TLS_INDEX,0);
55 SetSymbolValue(FREE_TLS_INDEX,
56 make_fixnum(fixnum_value(sym->tls_index)+1),0);
57 if(fixnum_value(sym->tls_index)>=TLS_SIZE) {
58 lose("Thread local storage exhausted.");
61 release_spinlock(tls_index_lock);
62 FSHOW_SIGNAL((stderr, "exiting dynbind tls alloc\n"));
63 clear_pseudo_atomic_atomic(th);
64 if (get_pseudo_atomic_interrupted(th))
65 do_pending_interrupt();
69 binding->value = SymbolTlValue(symbol, thread);
70 binding->symbol = symbol;
71 SetTlSymbolValue(symbol, value, thread);
77 struct thread *thread=(struct thread *)th;
78 struct binding *binding;
81 binding = GetBSP() - 1;
83 symbol = binding->symbol;
85 SetTlSymbolValue(symbol, binding->value,thread);
94 unbind_to_here(lispobj *bsp,void *th)
96 struct thread *thread=(struct thread *)th;
97 struct binding *target = (struct binding *)bsp;
98 struct binding *binding = GetBSP();
101 while (target < binding) {
104 symbol = binding->symbol;
106 if (symbol != UNBOUND_MARKER_WIDETAG) {
107 SetTlSymbolValue(symbol, binding->value,thread);