[ced29b]: src / runtime / dynbind.c Maximize Restore History

Download this file

dynbind.c    121 lines (106 with data), 3.6 kB

  1
  2
  3
  4
  5
  6
  7
  8
  9
 10
 11
 12
 13
 14
 15
 16
 17
 18
 19
 20
 21
 22
 23
 24
 25
 26
 27
 28
 29
 30
 31
 32
 33
 34
 35
 36
 37
 38
 39
 40
 41
 42
 43
 44
 45
 46
 47
 48
 49
 50
 51
 52
 53
 54
 55
 56
 57
 58
 59
 60
 61
 62
 63
 64
 65
 66
 67
 68
 69
 70
 71
 72
 73
 74
 75
 76
 77
 78
 79
 80
 81
 82
 83
 84
 85
 86
 87
 88
 89
 90
 91
 92
 93
 94
 95
 96
 97
 98
 99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
/*
* support for dynamic binding from C
* See the "Chapter 9: Specials" of the SBCL Internals Manual.
*/
/*
* This software is part of the SBCL system. See the README file for
* more information.
*
* This software is derived from the CMU CL system, which was
* written at Carnegie Mellon University and released into the
* public domain. The software is in the public domain and is
* provided with absolutely no warranty. See the COPYING and CREDITS
* files for more information.
*/
#include <stdio.h>
#include <stdlib.h>
#include "sbcl.h"
#include "runtime.h"
#include "globals.h"
#include "dynbind.h"
#include "thread.h"
#include "pseudo-atomic.h"
#include "genesis/symbol.h"
#include "genesis/binding.h"
#include "genesis/static-symbols.h"
void bind_variable(lispobj symbol, lispobj value, void *th)
{
struct binding *binding;
struct thread *thread=(struct thread *)th;
binding = (struct binding *)get_binding_stack_pointer(thread);
set_binding_stack_pointer(thread,binding+1);
#ifdef LISP_FEATURE_SB_THREAD
{
struct symbol *sym=(struct symbol *)native_pointer(symbol);
if(!sym->tls_index) {
lispobj *tls_index_lock=
&((struct symbol *)native_pointer(TLS_INDEX_LOCK))->value;
FSHOW_SIGNAL((stderr, "entering dynbind tls alloc\n"));
set_pseudo_atomic_atomic(thread);
get_spinlock(tls_index_lock,(uword_t)th);
if(!sym->tls_index) {
sym->tls_index=SymbolValue(FREE_TLS_INDEX,0);
SetSymbolValue(FREE_TLS_INDEX, sym->tls_index+N_WORD_BYTES, 0);
if((sym->tls_index)>=(TLS_SIZE << WORD_SHIFT)) {
lose("Thread local storage exhausted.");
}
}
release_spinlock(tls_index_lock);
FSHOW_SIGNAL((stderr, "exiting dynbind tls alloc\n"));
clear_pseudo_atomic_atomic(thread);
if (get_pseudo_atomic_interrupted(thread))
do_pending_interrupt();
}
binding->symbol = sym->tls_index;
binding->value = SymbolTlValue(symbol, thread);
}
#else
binding->symbol = symbol;
binding->value = SymbolTlValue(symbol, thread);
#endif
SetTlSymbolValue(symbol, value, thread);
}
void
unbind(void *th)
{
struct thread *thread=(struct thread *)th;
struct binding *binding;
lispobj symbol;
binding = ((struct binding *)get_binding_stack_pointer(thread)) - 1;
/* On sb-thread, it's actually a tls-index */
symbol = binding->symbol;
#ifdef LISP_FEATURE_SB_THREAD
((union per_thread_data *)thread)->dynamic_values[(symbol) >> WORD_SHIFT]
= binding->value;
#else
SetSymbolValue(symbol, binding->value, thread);
#endif
binding->symbol = 0;
binding->value = 0;
set_binding_stack_pointer(thread,binding);
}
void
unbind_to_here(lispobj *bsp,void *th)
{
struct thread *thread=(struct thread *)th;
struct binding *target = (struct binding *)bsp;
struct binding *binding = (struct binding *)get_binding_stack_pointer(thread);
lispobj symbol;
while (target < binding) {
binding--;
symbol = binding->symbol;
if (symbol) {
if (symbol != UNBOUND_MARKER_WIDETAG) {
#ifdef LISP_FEATURE_SB_THREAD
((union per_thread_data *)thread)->dynamic_values[(symbol) >> WORD_SHIFT]
= binding->value;
#else
SetSymbolValue(symbol, binding->value, thread);
#endif
}
binding->symbol = 0;
binding->value = 0;
}
}
set_binding_stack_pointer(thread,binding);
}