diff --git a/src/codegen/codegen_helper_visitor.cpp b/src/codegen/codegen_helper_visitor.cpp index 391dbc6d3..3ccee518d 100644 --- a/src/codegen/codegen_helper_visitor.cpp +++ b/src/codegen/codegen_helper_visitor.cpp @@ -252,7 +252,7 @@ void CodegenHelperVisitor::find_non_range_variables() { auto vars = psymtab->get_variables_with_properties(NmodlType::global_var); for (auto& var: vars) { - if (info.vectorize && info.thread_safe && var->get_write_count() > 0) { + if (info.vectorize && info.declared_thread_safe && var->get_write_count() > 0) { var->mark_thread_safe(); info.thread_variables.push_back(var); info.thread_var_data_size += var->get_length(); @@ -767,6 +767,10 @@ void CodegenHelperVisitor::visit_bbcore_pointer(const BbcorePointer& /* node */) info.bbcore_pointer_used = true; } +void CodegenHelperVisitor::visit_thread_safe(const ast::ThreadSafe&) { + info.declared_thread_safe = true; +} + void CodegenHelperVisitor::visit_watch(const ast::Watch& /* node */) { info.watch_count++; diff --git a/src/codegen/codegen_helper_visitor.hpp b/src/codegen/codegen_helper_visitor.hpp index 3468802c6..24d074f7a 100644 --- a/src/codegen/codegen_helper_visitor.hpp +++ b/src/codegen/codegen_helper_visitor.hpp @@ -101,6 +101,7 @@ class CodegenHelperVisitor: public visitor::ConstAstVisitor { void visit_derivimplicit_callback(const ast::DerivimplicitCallback& node) override; void visit_net_receive_block(const ast::NetReceiveBlock& node) override; void visit_bbcore_pointer(const ast::BbcorePointer& node) override; + void visit_thread_safe(const ast::ThreadSafe&) override; void visit_watch(const ast::Watch& node) override; void visit_watch_statement(const ast::WatchStatement& node) override; void visit_for_netcon(const ast::ForNetcon& node) override; diff --git a/src/codegen/codegen_info.hpp b/src/codegen/codegen_info.hpp index 0e86ac0c3..eaea56467 100644 --- a/src/codegen/codegen_info.hpp +++ b/src/codegen/codegen_info.hpp @@ -352,6 +352,12 @@ struct CodegenInfo { /// if mod file is thread safe (always true for coreneuron) bool thread_safe = true; + /// A mod file can be declared to be thread safe using the keyword THREADSAFE. + /// This boolean is true if and only if the mod file was declared thread safe + /// by the user. For example thread variables require the mod file to be declared + /// thread safe. + bool declared_thread_safe = false; + /// if mod file is point process bool point_process = false;