Skip to content

Commit

Permalink
Fix thread-safety issue when writing addon data. (#2611)
Browse files Browse the repository at this point in the history
Fix point count for addon data initialization.
Close #2610
  • Loading branch information
abellgithub committed Jul 12, 2019
1 parent 82402cf commit 87d9384
Showing 1 changed file with 7 additions and 4 deletions.
11 changes: 7 additions & 4 deletions io/EptReader.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -561,6 +561,7 @@ void EptReader::overlaps(const arbiter::Endpoint& ep,
else
{
{
//ABELL we could probably use a local mutex to lock the target map.
std::lock_guard<std::mutex> lock(m_mutex);
target[key] = static_cast<uint64_t>(numPoints);
}
Expand Down Expand Up @@ -595,16 +596,13 @@ PointViewSet EptReader::run(PointViewPtr view)
// Read addon information after the native data, we'll possibly
// overwrite attributes.
for (const auto& addon : m_addons)
{
readAddon(*view, key, *addon, startId);
}
});

++nodeId;
}

m_pool->await();

log()->get(LogLevel::Debug) << "Done reading!" << std::endl;

PointViewSet views;
Expand Down Expand Up @@ -716,7 +714,7 @@ void EptReader::process(PointView& dst, PointRef& pr, const uint64_t nodeId,
void EptReader::readAddon(PointView& dst, const Key& key, const Addon& addon,
const uint64_t pointId) const
{
const uint64_t np(addon.points(key));
uint64_t np(addon.points(key));
if (!np)
{
// If our addon has no points, then we are reading a superset of this
Expand All @@ -728,6 +726,10 @@ void EptReader::readAddon(PointView& dst, const Key& key, const Addon& addon,
// for an EPT-read of the full dataset. If the native EPT set already
// contains Classification, then we should overwrite it with zeroes
// where the addon leaves off.

std::lock_guard<std::mutex> lock(m_mutex);

np = m_overlaps.at(key);
for (uint64_t id(pointId); id < pointId + np; ++id)
{
dst.setField(addon.id(), id, 0);
Expand All @@ -748,6 +750,7 @@ void EptReader::readAddon(PointView& dst, const Key& key, const Addon& addon,
throwError("Invalid addon content length");
}

std::lock_guard<std::mutex> lock(m_mutex);
const char* pos(data.data());
for (uint64_t id(pointId); id < pointId + np; ++id)
{
Expand Down

0 comments on commit 87d9384

Please sign in to comment.