Skip to content

Commit

Permalink
Restore direct symbol global value access
Browse files Browse the repository at this point in the history
Used by Cando. It's fine I guess.

Should really be changed to a proper setf though.
  • Loading branch information
Bike committed Sep 25, 2023
1 parent 0f686f4 commit d5ca9a4
Show file tree
Hide file tree
Showing 2 changed files with 34 additions and 11 deletions.
22 changes: 11 additions & 11 deletions include/clasp/core/symbol.h
Original file line number Diff line number Diff line change
Expand Up @@ -108,10 +108,10 @@ class VariableCell_O : public General_O {
[[noreturn]] void unboundError() const;
public:
inline T_sp name() const { return this->_Name; }
inline T_sp globalValue() const {
inline T_sp globalValueUnsafe() const {
return _GlobalValue.load(std::memory_order_relaxed);
}
inline T_sp globalValueSeqCst() const {
inline T_sp globalValueUnsafeSeqCst() const {
return _GlobalValue.load();
}
inline void set_globalValue(T_sp val) {
Expand Down Expand Up @@ -140,7 +140,7 @@ class VariableCell_O : public General_O {
return bindings.thread_local_value(index);
else
#endif
return globalValue();
return globalValueUnsafe();
}
T_sp valueUnsafeSeqCst() const {
#ifdef CLASP_THREADS
Expand All @@ -150,7 +150,7 @@ class VariableCell_O : public General_O {
return bindings.thread_local_value(index);
else
#endif
return globalValueSeqCst();
return globalValueUnsafeSeqCst();
}
inline bool boundP() const { return !(valueUnsafe().unboundp()); }

Expand All @@ -170,6 +170,11 @@ class VariableCell_O : public General_O {
#endif
set_globalValue(value);
}
inline T_sp globalValue() const {
T_sp val = globalValueUnsafe();
if (val.unboundp()) unboundError();
else return val;
}
inline void makunbound() {
set_value(unbound<T_O>());
}
Expand Down Expand Up @@ -334,13 +339,8 @@ class Symbol_O : public General_O {
T_sp casSymbolValue(T_sp cmp, T_sp new_value);
bool boundP() const;

// TODO: Remove
inline T_sp threadLocalSymbolValue() {
return my_thread->_Bindings.thread_local_value(ensureVariableCell()->ensureBindingIndex());
}
inline void set_threadLocalSymbolValue(T_sp val) {
my_thread->_Bindings.set_thread_local_value(val, ensureVariableCell()->ensureBindingIndex());
}
T_sp globalSymbolValue() const;
void set_globalSymbolValue(T_sp nv);

void makunbound();

Expand Down
23 changes: 23 additions & 0 deletions src/core/symbol.cc
Original file line number Diff line number Diff line change
Expand Up @@ -162,6 +162,19 @@ CL_DEFUN T_sp cl__symbol_value(Symbol_sp arg) {
return arg->symbolValue();
};

DOCGROUP(clasp);
CL_DEFUN T_sp core__symbol_global_value(Symbol_sp s) {
return s->globalSymbolValue();
}

CL_DOCSTRING(R"(Set the value slot of the symbol to the value.
This bypasses thread local storage of symbol value slots and any threads that start
after this has been set will start with the value set here.)")
DOCGROUP(clasp);
CL_DEFUN void core__symbol_global_value_set(Symbol_sp sym, T_sp nv) {
sym->set_globalSymbolValue(nv);
}

CL_LAMBDA(symbol);
CL_DECLARE();
CL_DOCSTRING(R"dx(Sequentially-consistent atomic read of SYMBOL-VALUE.)dx");
Expand Down Expand Up @@ -303,12 +316,22 @@ T_sp Symbol_O::atomicSymbolValue() const {
else return vcell->value();
}

T_sp Symbol_O::globalSymbolValue() const {
VariableCell_sp vcell = variableCell();
if (vcell.unboundp())
UNBOUND_VARIABLE_ERROR(this->asSmartPtr());
else return vcell->globalValue();
}

void Symbol_O::setf_symbolValue(T_sp nv) {
ensureVariableCell()->set_value(nv);
}
void Symbol_O::set_atomicSymbolValue(T_sp nv) {
ensureVariableCell()->set_valueSeqCst(nv);
}
void Symbol_O::set_globalSymbolValue(T_sp nv) {
ensureVariableCell()->set_globalValue(nv);
}

T_sp Symbol_O::casSymbolValue(T_sp cmp, T_sp nv) {
return ensureVariableCell()->cas_globalValueSeqCst(cmp, nv);
Expand Down

0 comments on commit d5ca9a4

Please sign in to comment.