Skip to content

Commit 605e4d1

Browse files
committed
fix: rework thread safety (3)
1 parent bb17e32 commit 605e4d1

File tree

1 file changed

+6
-11
lines changed

1 file changed

+6
-11
lines changed

src/callback.cpp

Lines changed: 6 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -18,7 +18,7 @@ struct SimpleErrorHandler : ErrorHandler {
1818
using namespace PLH;
1919

2020
static JitRuntime rt;
21-
static thread_local std::map<const Callback*, std::array<plg::any, Globals::kMaxFuncArgs>> storage;
21+
static thread_local std::map<const Callback*, std::array<plg::any, Globals::kMaxFuncArgs + 1>> storage;
2222

2323
struct ArgRegSlot {
2424
explicit ArgRegSlot(uint32_t idx) {
@@ -475,26 +475,21 @@ std::string_view Callback::getError() const noexcept {
475475
}
476476

477477
plg::any& Callback::setStorage(size_t idx, const plg::any& any) const {
478-
if (idx == -1) {
479-
idx = 32;
480-
}
481-
storage[this][idx] = any;
482-
return storage[this][idx];
478+
auto& var = storage[this][++idx];
479+
var = any;
480+
return var;
483481
}
484482

485483
plg::any& Callback::getStorage(size_t idx) const {
486-
if (idx == -1) {
487-
idx = 32;
488-
}
489-
return storage[this][idx];
484+
return storage[this][++idx];
490485
}
491486

492487
DataType Callback::getReturnType() const {
493488
return m_returnType;
494489
}
495490

496491
DataType Callback::getArgumentType(size_t idx) const {
497-
return m_arguments[idx];
492+
return m_arguments[++idx];
498493
}
499494

500495
Callback::Callback(DataType returnType, std::span<const DataType> arguments) : m_returnType(returnType), m_arguments(arguments.begin(), arguments.end()) {

0 commit comments

Comments
 (0)