Skip to content

Commit

Permalink
bugfix rasterize and test threading
Browse files Browse the repository at this point in the history
  • Loading branch information
rafaqz committed Oct 21, 2023
1 parent b83a6f2 commit 6441f08
Show file tree
Hide file tree
Showing 3 changed files with 135 additions and 118 deletions.
6 changes: 4 additions & 2 deletions src/methods/coverage.jl
Original file line number Diff line number Diff line change
Expand Up @@ -93,9 +93,10 @@ function _coverage!(A::AbstractRaster, ::GI.AbstractGeometryTrait, geom, r; scal
return A
end
function _coverage!(A::AbstractRaster, ::Nothing, geoms, r::Rasterizer; mode, scale)
n = _nthreads()
n = r.threaded ? _nthreads() : 1
buffers = (
allocs = _burning_allocs(A; threaded=r.threaded),
# We always need a vector of threads, but just
allocs = _burning_allocs(A; nthreads=n, threaded=true),
linebuffer = [_init_bools(A, BitArray; missingval=false) for _ in 1:n],
centerbuffer = [_init_bools(A, BitArray; missingval=false) for _ in 1:n],
block_crossings = [[Vector{Float64}(undef, 0) for _ in 1:scale] for _ in 1:n],
Expand Down Expand Up @@ -130,6 +131,7 @@ function _union_coverage!(A::AbstractRaster, geoms, buffers;
_run(range, threaded, progress, "Calculating coverage buffers...") do i
geom = _getgeom(geoms, i)
idx = Threads.threadid()
# Get buffers for each thread as a NamedTuple
thread_buffers = map(b -> b[idx], allbuffers)
_union_coverage!(A, geom; scale, subpixel_buffer, thread_buffers...)
fill!(thread_buffers.linebuffer, false)
Expand Down
6 changes: 1 addition & 5 deletions src/methods/rasterize.jl
Original file line number Diff line number Diff line change
Expand Up @@ -584,11 +584,7 @@ end
# Fill points
function _rasterize!(A, trait::GI.AbstractPointTrait, point, fill, r::Rasterizer; allocs=nothing)
# Avoid race conditions whern Point is in a mixed set of Geometries
isnothing(r.lock) || Base.lock(r.lock)
hasburned = _fill_point!(A, trait, point; fill, r.lock)
isnothing(r.lock) || Base.unlock(r.lock)
# for all points we avoid parallel rasterization completely - this method should not be hit often
return hasburned
return _fill_point!(A, trait, point; fill, r.lock)
end
function _rasterize!(A, trait::Nothing, geoms, fill, r::Rasterizer; allocs=nothing)
if r.shape === :point
Expand Down
Loading

0 comments on commit 6441f08

Please sign in to comment.