@@ -49,10 +49,10 @@ Scope& Scope::NewScope() const {
49
49
}
50
50
51
51
Variable* Scope::Var (const std::string& name) {
52
- auto * v = FindVarLocally (name);
53
- if (v != nullptr ) return v;
54
52
// acquire the lock when new var under this scope
55
53
std::unique_lock<std::mutex> lock (mutex_);
54
+ auto * v = FindVarLocally (name);
55
+ if (v != nullptr ) return v;
56
56
v = new Variable ();
57
57
vars_[name] = v;
58
58
VLOG (3 ) << " Create variable " << name;
@@ -69,11 +69,17 @@ Variable* Scope::Var(std::string* name) {
69
69
}
70
70
71
71
Variable* Scope::FindVar (const std::string& name) const {
72
+ // acquire the lock when find var
73
+ std::unique_lock<std::mutex> lock (mutex_);
74
+ return FindVarInternal (name);
75
+ }
76
+
77
+ Variable* Scope::FindVarInternal (const std::string& name) const {
72
78
auto var = FindVarLocally (name);
73
79
if (var != nullptr ) {
74
80
return var;
75
81
}
76
- return (parent_ == nullptr ) ? nullptr : parent_->FindVar (name);
82
+ return (parent_ == nullptr ) ? nullptr : parent_->FindVarInternal (name);
77
83
}
78
84
79
85
const Scope* Scope::FindScope (const Variable* var) const {
@@ -144,8 +150,6 @@ std::string Scope::Rename(const std::string& origin_name) const {
144
150
}
145
151
146
152
Variable* Scope::FindVarLocally (const std::string& name) const {
147
- // acquire the lock when find locally
148
- std::unique_lock<std::mutex> lock (mutex_);
149
153
auto it = vars_.find (name);
150
154
if (it != vars_.end ()) return it->second ;
151
155
return nullptr ;
0 commit comments