move @running into init_producer

This commit is contained in:
onyx-and-iris 2023-08-03 11:04:13 +01:00
parent cb09e5ea2d
commit a754e3b9ea

View File

@ -7,7 +7,9 @@ module Voicemeeter
include Logging include Logging
def init_producer(que) def init_producer(que)
@running = true
Thread.new do Thread.new do
Thread.current.name = "producer"
while @running while @running
que << :pdirty if event.pdirty que << :pdirty if event.pdirty
que << :mdirty if event.mdirty que << :mdirty if event.mdirty
@ -15,7 +17,7 @@ module Voicemeeter
que << :ldirty if event.ldirty que << :ldirty if event.ldirty
sleep(@ratelimit) sleep(@ratelimit)
end end
logger.debug "closing producer thread" logger.debug "closing #{Thread.current.name} thread"
que << :stop que << :stop
end end
end end
@ -25,12 +27,12 @@ module Voicemeeter
@cache[:strip_level], @cache[:bus_level] = _get_levels @cache[:strip_level], @cache[:bus_level] = _get_levels
@cache[:strip_comp] = Array.new(kind.num_strip_levels, false) @cache[:strip_comp] = Array.new(kind.num_strip_levels, false)
@cache[:bus_comp] = Array.new(kind.num_bus_levels, false) @cache[:bus_comp] = Array.new(kind.num_bus_levels, false)
@running = true
Thread.new do Thread.new do
Thread.current.name = "worker"
loop do loop do
e_from_que = @que.pop e_from_que = @que.pop
if e_from_que == :stop if e_from_que == :stop
logger.debug "closing worker thread" logger.debug "closing #{Thread.current.name} thread"
break break
end end
trigger :on_pdirty if e_from_que == :pdirty && pdirty? trigger :on_pdirty if e_from_que == :pdirty && pdirty?