Skip to content

Commit

Permalink
Resolve data races found by ThreadSanitizer
Browse files Browse the repository at this point in the history
Signed-off-by: Eryk Szpotanski <[email protected]>
Co-authored-by: Krzysztof Bieganski <[email protected]>
  • Loading branch information
eszpotanski and kbieganski committed Nov 21, 2024
1 parent 70d52c2 commit 4ccc9d8
Show file tree
Hide file tree
Showing 2 changed files with 25 additions and 10 deletions.
23 changes: 18 additions & 5 deletions graph/Graph.cc
Original file line number Diff line number Diff line change
Expand Up @@ -586,6 +586,7 @@ Graph::makeArrivals(Vertex *vertex,
Arrival *
Graph::arrivals(Vertex *vertex)
{
LockGuard lock(arrivals_lock_);
return arrivals_.pointer(vertex->arrivals());
}

Expand Down Expand Up @@ -619,6 +620,7 @@ Graph::makeRequireds(Vertex *vertex,
Required *
Graph::requireds(Vertex *vertex)
{
LockGuard lock(requireds_lock_);
return requireds_.pointer(vertex->requireds());
}

Expand Down Expand Up @@ -650,6 +652,7 @@ Graph::makePrevPaths(Vertex *vertex,
PathVertexRep *
Graph::prevPaths(Vertex *vertex) const
{
LockGuard lock(prev_paths_lock_);
return prev_paths_.pointer(vertex->prevPaths());
}

Expand Down Expand Up @@ -1352,20 +1355,30 @@ Vertex::setHasDownstreamClkPin(bool has_clk_pin)
has_downstream_clk_pin_ = has_clk_pin;
}

#define IN_QUEUE(mask, index) (mask & (1 << unsigned(index)))
#define SET_IN_QUEUE(mask, index) ((mask) |= (1 << unsigned(index)))
#define CLEAR_IN_QUEUE(mask, index) ((mask) &= ~(1 << unsigned(index)))

bool
Vertex::bfsInQueue(BfsIndex index) const
{
return (bfs_in_queue_ >> unsigned(index)) & 1;
return IN_QUEUE(bfs_in_queue_, index);
}

void
Vertex::setBfsInQueue(BfsIndex index,
bool value)
{
if (value)
bfs_in_queue_ |= 1 << int(index);
else
bfs_in_queue_ &= ~(1 << int(index));
unsigned char expected = bfs_in_queue_;
unsigned char desired;
do {
if ((value && IN_QUEUE(expected, index)) || (!value && !IN_QUEUE(expected, index))) {
return;
}
desired = expected;
SET_IN_QUEUE(value ? desired : expected, index);
CLEAR_IN_QUEUE(value ? expected : desired, index);
} while (!bfs_in_queue_.compare_exchange_weak(expected, desired));
}

////////////////////////////////////////////////////////////////
Expand Down
12 changes: 7 additions & 5 deletions include/sta/Graph.hh
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,7 @@

#pragma once

#include <atomic>
#include <mutex>

#include "Iterator.hh"
Expand Down Expand Up @@ -253,7 +254,7 @@ protected:
RequiredsTable requireds_;
std::mutex requireds_lock_;
PrevPathsTable prev_paths_;
std::mutex prev_paths_lock_;
mutable std::mutex prev_paths_lock_;
Vector<bool> arc_delay_annotated_;
int slew_rf_count_;
bool have_arc_delays_;
Expand Down Expand Up @@ -357,10 +358,10 @@ protected:
EdgeId out_edges_; // Edges from this vertex.

// 32 bits
unsigned int tag_group_index_:tag_group_index_bits; // 24
unsigned int tag_group_index_; // >= tag_group_index_bits = 24
// Each bit corresponds to a different BFS queue.
unsigned int bfs_in_queue_:int(BfsIndex::bits); // 4
unsigned int slew_annotated_:slew_annotated_bits;
std::atomic<unsigned char> bfs_in_queue_; // >= int(BfsIndex::bits) = 4
unsigned char object_idx_; // >= VertexTable::idx_bits = 7

// 32 bits
unsigned int level_:Graph::vertex_level_bits;
Expand All @@ -385,7 +386,8 @@ protected:
bool has_downstream_clk_pin_:1;
bool crpr_path_pruning_disabled_:1;
bool requireds_pruned_:1;
unsigned object_idx_:VertexTable::idx_bits;

unsigned int slew_annotated_:slew_annotated_bits;

private:
friend class Graph;
Expand Down

0 comments on commit 4ccc9d8

Please sign in to comment.