diff options
author | Sergiusz Bazanski <q3k@q3k.org> | 2018-07-13 12:35:39 +0100 |
---|---|---|
committer | Sergiusz Bazanski <q3k@q3k.org> | 2018-07-13 12:35:39 +0100 |
commit | 0816f447b768ebe0632f419e9b696714dda4e860 (patch) | |
tree | 2001dd1ba033d8cd535c8c72a078f71b5fee757b /ice40/arch.cc | |
parent | 309a533b7c5eab79addfc2b1733d39c1b48d9aae (diff) | |
download | nextpnr-0816f447b768ebe0632f419e9b696714dda4e860.tar.gz nextpnr-0816f447b768ebe0632f419e9b696714dda4e860.tar.bz2 nextpnr-0816f447b768ebe0632f419e9b696714dda4e860.zip |
Make ice40::Arch thread-safe
We move all non-chip data to be private and guard them with an R/W
mutex.
We then modify all calls that access these fields to lock/shared_lock
the mutex as required.
Profiling the code before and after is an exercise left to the reader
:).
Diffstat (limited to 'ice40/arch.cc')
-rw-r--r-- | ice40/arch.cc | 7 |
1 files changed, 7 insertions, 0 deletions
diff --git a/ice40/arch.cc b/ice40/arch.cc index 786bf686..88a900d8 100644 --- a/ice40/arch.cc +++ b/ice40/arch.cc @@ -241,6 +241,7 @@ IdString Arch::archArgsToId(ArchArgs args) const BelId Arch::getBelByName(IdString name) const { + boost::lock_guard<boost::shared_mutex> lock(mtx_); BelId ret; if (bel_by_name.empty()) { @@ -276,6 +277,7 @@ BelRange Arch::getBelsAtSameTile(BelId bel) const WireId Arch::getWireBelPin(BelId bel, PortPin pin) const { WireId ret; + boost::shared_lock_guard<boost::shared_mutex> lock(mtx_); NPNR_ASSERT(bel != BelId()); @@ -296,6 +298,7 @@ WireId Arch::getWireBelPin(BelId bel, PortPin pin) const WireId Arch::getWireByName(IdString name) const { WireId ret; + boost::shared_lock_guard<boost::shared_mutex> lock(mtx_); if (wire_by_name.empty()) { for (int i = 0; i < chip_info->num_wires; i++) @@ -314,6 +317,7 @@ WireId Arch::getWireByName(IdString name) const PipId Arch::getPipByName(IdString name) const { PipId ret; + boost::shared_lock_guard<boost::shared_mutex> lock(mtx_); if (pip_by_name.empty()) { for (int i = 0; i < chip_info->num_pips; i++) { @@ -372,6 +376,8 @@ std::string Arch::getBelPackagePin(BelId bel) const // ----------------------------------------------------------------------- +// TODO(cliffordvienna): lock all of this + GroupId Arch::getGroupByName(IdString name) const { for (auto g : getGroups()) @@ -488,6 +494,7 @@ DecalXY Arch::getGroupDecal(GroupId group) const std::vector<GraphicElement> Arch::getDecalGraphics(DecalId decal) const { + boost::shared_lock_guard<boost::shared_mutex> lock(mtx_); std::vector<GraphicElement> ret; if (decal.type == DecalId::TYPE_FRAME) { |