From 5df616e1b32bd997d48af849fa2c0c277636d65e Mon Sep 17 00:00:00 2001 From: Nathanne Isip Date: Sat, 28 Sep 2024 04:58:27 +0800 Subject: [PATCH] Implementation for SymbolTable for mutex lock guarding. --- src/core/SymbolTable.cpp | 5 +++++ 1 file changed, 5 insertions(+) diff --git a/src/core/SymbolTable.cpp b/src/core/SymbolTable.cpp index 185a77a..6365db6 100644 --- a/src/core/SymbolTable.cpp +++ b/src/core/SymbolTable.cpp @@ -47,6 +47,8 @@ DynamicObject SymbolTable::getSymbol( } void SymbolTable::setSymbol(const std::string& name, DynamicObject value) { + std::lock_guard lock(this->mtx); + if(this->hasSymbol(name)) this->table[name] = value; else if(this->parent && this->parent->hasSymbol(name)) @@ -56,6 +58,7 @@ void SymbolTable::setSymbol(const std::string& name, DynamicObject value) { } bool SymbolTable::hasSymbol(const std::string& name) { + std::lock_guard lock(this->mtx); return this->table.find(name) != this->table.end() || (this->parent && this->parent->hasSymbol(name)); } @@ -73,6 +76,7 @@ void SymbolTable::waitForThreads() { thread.join(); this->threads.clear(); + this->mtx.unlock(); } void SymbolTable::detachParallelNodes() { @@ -83,4 +87,5 @@ void SymbolTable::detachParallelNodes() { thread.detach(); this->threads.clear(); + this->mtx.unlock(); } \ No newline at end of file