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.
21 #include "pseudo-atomic.h"
22 #include "genesis/symbol.h"
23 #include "genesis/binding.h"
24 #include "genesis/thread.h"
25 #include "genesis/static-symbols.h"
27 #if defined(BINDING_STACK_POINTER)
28 #define GetBSP() ((struct binding *)SymbolValue(BINDING_STACK_POINTER,thread))
29 #define SetBSP(value) SetSymbolValue(BINDING_STACK_POINTER, (lispobj)(value),thread)
31 #define GetBSP() ((struct binding *)current_binding_stack_pointer)
32 #define SetBSP(value) (current_binding_stack_pointer=(lispobj *)(value))
35 void bind_variable(lispobj symbol, lispobj value, void *th)
37 struct binding *binding;
38 struct thread *thread=(struct thread *)th;
41 #ifdef LISP_FEATURE_SB_THREAD
43 struct symbol *sym=(struct symbol *)native_pointer(symbol);
45 lispobj *tls_index_lock=
46 &((struct symbol *)native_pointer(TLS_INDEX_LOCK))->value;
47 clear_pseudo_atomic_interrupted(th);
48 set_pseudo_atomic_atomic(th);
49 get_spinlock(tls_index_lock,(long)th);
51 sym->tls_index=SymbolValue(FREE_TLS_INDEX,0);
52 SetSymbolValue(FREE_TLS_INDEX,
53 make_fixnum(fixnum_value(sym->tls_index)+1),0);
55 release_spinlock(tls_index_lock);
56 clear_pseudo_atomic_atomic(th);
57 if (get_pseudo_atomic_interrupted(th))
58 do_pending_interrupt();
62 binding->value = SymbolTlValue(symbol, thread);
63 binding->symbol = symbol;
64 SetTlSymbolValue(symbol, value, thread);
70 struct thread *thread=(struct thread *)th;
71 struct binding *binding;
74 binding = GetBSP() - 1;
76 symbol = binding->symbol;
78 SetTlSymbolValue(symbol, binding->value,thread);
86 unbind_to_here(lispobj *bsp,void *th)
88 struct thread *thread=(struct thread *)th;
89 struct binding *target = (struct binding *)bsp;
90 struct binding *binding = GetBSP();
93 while (target < binding) {
96 symbol = binding->symbol;
98 SetTlSymbolValue(symbol, binding->value,thread);