Skip to content

Commit

Permalink
Make index creation threadsafe (#572)
Browse files Browse the repository at this point in the history
Signed-off-by: Martin Davis <[email protected]>
  • Loading branch information
dr-jts authored Aug 6, 2020
1 parent 06cd292 commit 29b00ec
Showing 1 changed file with 12 additions and 5 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -79,11 +79,7 @@ public IndexedPointInAreaLocator(Geometry g)
*/
public int locate(Coordinate p)
{
if (index == null) {
index = new IntervalIndexedGeometry(geom);
// no need to hold onto geom
geom = null;
}
createIndex();
RayCrossingCounter rcc = new RayCrossingCounter(p);

SegmentVisitor visitor = new SegmentVisitor(rcc);
Expand All @@ -97,6 +93,17 @@ public int locate(Coordinate p)

return rcc.getLocation();
}

/**
* Creates the indexed geometry, creating it if necessary.
*/
private synchronized void createIndex() {
if (index == null) {
index = new IntervalIndexedGeometry(geom);
// no need to hold onto geom
geom = null;
}
}

private static class SegmentVisitor
implements ItemVisitor
Expand Down

0 comments on commit 29b00ec

Please sign in to comment.