debrew: migrate away from mutex_m

This commit is contained in:
Bo Anderson 2025-04-15 23:02:00 +01:00
parent 0046519c08
commit 31c4116a78
No known key found for this signature in database

View File

@ -1,13 +1,10 @@
# typed: true # rubocop:todo Sorbet/StrictSigil # typed: true # rubocop:todo Sorbet/StrictSigil
# frozen_string_literal: true # frozen_string_literal: true
require "mutex_m"
require "ignorable" require "ignorable"
# Helper module for debugging formulae. # Helper module for debugging formulae.
module Debrew module Debrew
extend Mutex_m
# Module for allowing to debug formulae. # Module for allowing to debug formulae.
module Formula module Formula
def install def install
@ -68,18 +65,18 @@ module Debrew
end end
end end
@active = false @mutex = nil
@debugged_exceptions = Set.new @debugged_exceptions = Set.new
class << self class << self
attr_reader :debugged_exceptions attr_reader :debugged_exceptions
sig { returns(T::Boolean) } sig { returns(T::Boolean) }
def active? = @active def active? = !@mutex.nil?
end end
def self.debrew def self.debrew
@active = true @mutex = Mutex.new
Ignorable.hook_raise Ignorable.hook_raise
begin begin
@ -90,12 +87,12 @@ module Debrew
e.ignore if debug(e) == :ignore # execution jumps back to where the exception was thrown e.ignore if debug(e) == :ignore # execution jumps back to where the exception was thrown
ensure ensure
Ignorable.unhook_raise Ignorable.unhook_raise
@active = false @mutex = nil
end end
end end
def self.debug(exception) def self.debug(exception)
raise(exception) if !active? || !debugged_exceptions.add?(exception) || !mu_try_lock raise(exception) if !active? || !debugged_exceptions.add?(exception) || !@mutex.try_lock
begin begin
puts exception.backtrace.first puts exception.backtrace.first
@ -115,7 +112,7 @@ module Debrew
set_trace_func proc { |event, _, _, id, binding, klass| set_trace_func proc { |event, _, _, id, binding, klass|
if klass == Object && id == :raise && event == "return" if klass == Object && id == :raise && event == "return"
set_trace_func(nil) set_trace_func(nil)
mu_synchronize do @mutex.synchronize do
require "debrew/irb" require "debrew/irb"
IRB.start_within(binding) IRB.start_within(binding)
end end
@ -133,7 +130,7 @@ module Debrew
end end
end end
ensure ensure
mu_unlock @mutex.unlock
end end
end end
end end