Skip to content

Commit aa94722

Browse files
eszpotanskikbieganski
authored andcommitted
Resolve data races found by ThreadSanitizer
Signed-off-by: Eryk Szpotanski <[email protected]> Co-authored-by: Krzysztof Bieganski <[email protected]>
1 parent b8b67ba commit aa94722

File tree

2 files changed

+16
-6
lines changed

2 files changed

+16
-6
lines changed

graph/Graph.cc

Lines changed: 15 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1248,20 +1248,30 @@ Vertex::setHasDownstreamClkPin(bool has_clk_pin)
12481248
has_downstream_clk_pin_ = has_clk_pin;
12491249
}
12501250

1251+
#define IN_QUEUE(mask, index) (mask & (1 << unsigned(index)))
1252+
#define SET_IN_QUEUE(mask, index) ((mask) |= (1 << unsigned(index)))
1253+
#define CLEAR_IN_QUEUE(mask, index) ((mask) &= ~(1 << unsigned(index)))
1254+
12511255
bool
12521256
Vertex::bfsInQueue(BfsIndex index) const
12531257
{
1254-
return (bfs_in_queue_ >> unsigned(index)) & 1;
1258+
return IN_QUEUE(bfs_in_queue_, index);
12551259
}
12561260

12571261
void
12581262
Vertex::setBfsInQueue(BfsIndex index,
12591263
bool value)
12601264
{
1261-
if (value)
1262-
bfs_in_queue_ |= 1 << int(index);
1263-
else
1264-
bfs_in_queue_ &= ~(1 << int(index));
1265+
unsigned char expected = bfs_in_queue_;
1266+
unsigned char desired;
1267+
do {
1268+
if ((value && IN_QUEUE(expected, index)) || (!value && !IN_QUEUE(expected, index))) {
1269+
return;
1270+
}
1271+
desired = expected;
1272+
SET_IN_QUEUE(value ? desired : expected, index);
1273+
CLEAR_IN_QUEUE(value ? expected : desired, index);
1274+
} while (!bfs_in_queue_.compare_exchange_weak(expected, desired));
12651275
}
12661276

12671277
////////////////////////////////////////////////////////////////

include/sta/Graph.hh

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -368,7 +368,7 @@ protected:
368368
bool has_downstream_clk_pin_:1;
369369
bool crpr_path_pruning_disabled_:1;
370370
bool requireds_pruned_:1;
371-
unsigned object_idx_:VertexTable::idx_bits; // 7
371+
unsigned char object_idx_; // >= VertexTable::idx_bits = 7
372372

373373
private:
374374
friend class Graph;

0 commit comments

Comments
 (0)