Skip to content

Commit

Permalink
Don't try to read when there is nothing to read.
Browse files Browse the repository at this point in the history
  • Loading branch information
abellgithub committed Oct 19, 2020
1 parent d46846c commit 5d016dc
Showing 1 changed file with 19 additions and 16 deletions.
35 changes: 19 additions & 16 deletions io/EptReader.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -710,24 +710,27 @@ point_count_t EptReader::read(PointViewPtr view, point_count_t count)

point_count_t numRead = 0;

// Pop tiles until there are no more, or wait for them to appear.
// Exit when we've handled all the tiles or we've read enough points.
do
if (m_p->hierarchy->size())
{
std::unique_lock<std::mutex> l(m_p->mutex);
if (m_p->contents.size())
// Pop tiles until there are no more, or wait for them to appear.
// Exit when we've handled all the tiles or we've read enough points.
do
{
TileContents tile = std::move(m_p->contents.front());
m_p->contents.pop();
l.unlock();
checkTile(tile);
process(view, tile, count - numRead);
numRead += tile.size();
m_tileCount--;
}
else
m_p->contentsCv.wait(l);
} while (m_tileCount && numRead <= count);
std::unique_lock<std::mutex> l(m_p->mutex);
if (m_p->contents.size())
{
TileContents tile = std::move(m_p->contents.front());
m_p->contents.pop();
l.unlock();
checkTile(tile);
process(view, tile, count - numRead);
numRead += tile.size();
m_tileCount--;
}
else
m_p->contentsCv.wait(l);
} while (m_tileCount && numRead <= count);
}

// Wait for any running threads to finish and don't start any others.
// Only relevant if we hit the count limit before reading all the tiles.
Expand Down

0 comments on commit 5d016dc

Please sign in to comment.