Skip to content
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@
* raise Vips::Error if `copy_memory` fails [VitaliiLazebnyi]
* `Source.new_from_memory` keeps a reference to the memory area [jeremy]
* release the GVL during `copy_memory` and `write_to_memory` [andrewfader]
* release the GVL during `Region#fetch` [janko]

## Version 2.3.0 (2025-12-10)

Expand Down
4 changes: 3 additions & 1 deletion lib/vips/region.rb
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,9 @@ module Vips
attach_function :vips_region_new, [:pointer], :pointer

if Vips.at_least_libvips?(8, 8)
attach_function :vips_region_fetch, [:pointer, :int, :int, :int, :int, SizeStruct.ptr], :pointer
# fetch evaluates the pipeline, so release the GVL while it runs
attach_function :vips_region_fetch, [:pointer, :int, :int, :int, :int, SizeStruct.ptr], :pointer,
blocking: true
attach_function :vips_region_width, [:pointer], :int
attach_function :vips_region_height, [:pointer], :int
end
Expand Down
25 changes: 25 additions & 0 deletions spec/region_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -26,4 +26,29 @@
expect(region.width == 30)
expect(region.height == 40)
end

# fetch evaluates the pipeline, so it must release the GVL, or every other
# Ruby thread stalls until it returns
it "lets other threads run during fetch", version: [8, 8] do
image = Vips::Image.gaussnoise(2000, 2000).gaussblur(4)
region = Vips::Region.new image

ticks = 0
running = true
ticker = Thread.new do
while running
ticks += 1
sleep 0.001
end
end
sleep 0.01 until ticks > 0

before = ticks
region.fetch(0, 0, 2000, 2000)
during = ticks - before
running = false
ticker.join

expect(during).to be > 0
end
end