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,
48 make_fixnum(fixnum_value(sym->tls_index)+1),0);
49 if(fixnum_value(sym->tls_index)>=TLS_SIZE) {
50 lose("Thread local storage exhausted.");
53 release_spinlock(tls_index_lock);
54 FSHOW_SIGNAL((stderr, "exiting dynbind tls alloc\n"));
55 clear_pseudo_atomic_atomic(thread);
56 if (get_pseudo_atomic_interrupted(thread))
57 do_pending_interrupt();
61 binding->value = SymbolTlValue(symbol, thread);
62 binding->symbol = symbol;
63 SetTlSymbolValue(symbol, value, thread);
69 struct thread *thread=(struct thread *)th;
70 struct binding *binding;
73 binding = ((struct binding *)get_binding_stack_pointer(thread)) - 1;
75 symbol = binding->symbol;
77 SetTlSymbolValue(symbol, binding->value,thread);
82 set_binding_stack_pointer(thread,binding);
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 = (struct binding *)get_binding_stack_pointer(thread);
93 while (target < binding) {
96 symbol = binding->symbol;
98 if (symbol != UNBOUND_MARKER_WIDETAG) {
99 SetTlSymbolValue(symbol, binding->value,thread);
105 set_binding_stack_pointer(thread,binding);