Skip to content

Commit a38b8b0

Browse files
gautvenktomflynn
authored andcommitted
Address tsan warning: protecting flowmod changes with a mutex in test code
Signed-off-by: Gautam Venkataramanan <gautam.chennai@gmail.com> Change-Id: I286fdef4029d02441a45a91383f45af534dabf32
1 parent c4969b7 commit a38b8b0

File tree

2 files changed

+17
-4
lines changed

2 files changed

+17
-4
lines changed

agent-ovs/ovs/test/MockFlowExecutor.cpp

Lines changed: 16 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -51,6 +51,7 @@ MockFlowExecutor::MockFlowExecutor()
5151
: ignoreFlowMods(true), ignoreGroupMods(true), ignoreTlvMods(true) {}
5252

5353
bool MockFlowExecutor::Execute(const FlowEdit& flowEdits) {
54+
std::lock_guard<std::mutex> guard(flow_mod_mutex);
5455
if (ignoreFlowMods) return true;
5556

5657
FlowEdit editCopy = flowEdits;
@@ -121,10 +122,12 @@ bool MockFlowExecutor::Execute(const TlvEdit& TlvEdits) {
121122
return true;
122123
}
123124
void MockFlowExecutor::Expect(FlowEdit::type mod, const string& fe) {
125+
std::lock_guard<std::mutex> guard(flow_mod_mutex);
124126
ignoreFlowMods = false;
125127
flowMods.push_back(mod_t(mod, fe));
126128
}
127129
void MockFlowExecutor::Expect(FlowEdit::type mod, const vector<string>& fe) {
130+
std::lock_guard<std::mutex> guard(flow_mod_mutex);
128131
ignoreFlowMods = false;
129132
for (const string& s : fe)
130133
flowMods.push_back(mod_t(mod, s));
@@ -145,6 +148,7 @@ void MockFlowExecutor::IgnoreTlvMods() {
145148
tlvMods.clear();
146149
}
147150
void MockFlowExecutor::IgnoreFlowMods() {
151+
std::lock_guard<std::mutex> guard(flow_mod_mutex);
148152
ignoreFlowMods = true;
149153
flowMods.clear();
150154
}
@@ -153,16 +157,24 @@ void MockFlowExecutor::IgnoreGroupMods() {
153157
ignoreGroupMods = true;
154158
groupMods.clear();
155159
}
156-
bool MockFlowExecutor::IsEmpty() { return flowMods.empty() || ignoreFlowMods; }
160+
bool MockFlowExecutor::IsEmpty() {
161+
std::lock_guard<std::mutex> guard(flow_mod_mutex);
162+
return flowMods.empty() || ignoreFlowMods;
163+
}
157164
bool MockFlowExecutor::IsGroupEmpty() {
158165
std::lock_guard<std::mutex> guard(group_mod_mutex);
159166
return groupMods.empty() || ignoreGroupMods;
160167
}
161168
bool MockFlowExecutor::IsTlvEmpty() { return tlvMods.empty() || ignoreTlvMods; }
162169
void MockFlowExecutor::Clear() {
163-
std::lock_guard<std::mutex> guard(group_mod_mutex);
164-
flowMods.clear();
165-
groupMods.clear();
170+
{
171+
std::lock_guard<std::mutex> guard(flow_mod_mutex);
172+
flowMods.clear();
173+
}
174+
{
175+
std::lock_guard<std::mutex> guard(group_mod_mutex);
176+
groupMods.clear();
177+
}
166178
tlvMods.clear();
167179
}
168180

agent-ovs/ovs/test/include/MockFlowExecutor.h

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -51,6 +51,7 @@ class MockFlowExecutor : public FlowExecutor {
5151
bool ignoreFlowMods;
5252
std::unordered_set<int> ignoredFlowMods;
5353
std::mutex group_mod_mutex;
54+
std::mutex flow_mod_mutex;
5455
bool ignoreGroupMods;
5556
bool ignoreTlvMods;
5657
};

0 commit comments

Comments
 (0)