Skip to content

Commit

Permalink
Implementation for SymbolTable for mutex lock guarding.
Browse files Browse the repository at this point in the history
  • Loading branch information
nthnn committed Sep 27, 2024
1 parent e47deda commit 5df616e
Showing 1 changed file with 5 additions and 0 deletions.
5 changes: 5 additions & 0 deletions src/core/SymbolTable.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -47,6 +47,8 @@ DynamicObject SymbolTable::getSymbol(
}

void SymbolTable::setSymbol(const std::string& name, DynamicObject value) {
std::lock_guard<std::mutex> lock(this->mtx);

if(this->hasSymbol(name))
this->table[name] = value;
else if(this->parent && this->parent->hasSymbol(name))
Expand All @@ -56,6 +58,7 @@ void SymbolTable::setSymbol(const std::string& name, DynamicObject value) {
}

bool SymbolTable::hasSymbol(const std::string& name) {
std::lock_guard<std::mutex> lock(this->mtx);
return this->table.find(name) != this->table.end() ||
(this->parent && this->parent->hasSymbol(name));
}
Expand All @@ -73,6 +76,7 @@ void SymbolTable::waitForThreads() {
thread.join();

this->threads.clear();
this->mtx.unlock();
}

void SymbolTable::detachParallelNodes() {
Expand All @@ -83,4 +87,5 @@ void SymbolTable::detachParallelNodes() {
thread.detach();

this->threads.clear();
this->mtx.unlock();
}

0 comments on commit 5df616e

Please sign in to comment.