Skip to content

Commit

Permalink
Support Thread#native_thread_id only when available on platform
Browse files Browse the repository at this point in the history
  • Loading branch information
mblumtritt committed May 30, 2024
1 parent b3e299b commit 61d752c
Showing 1 changed file with 14 additions and 11 deletions.
25 changes: 14 additions & 11 deletions lib/im-lost.rb
Original file line number Diff line number Diff line change
Expand Up @@ -392,16 +392,9 @@ def _instance_vars(object)
end

def _thread_identifier(thread)
if thread.native_thread_id
return(
"#{thread.status} Thread #{thread.native_thread_id} #{
thread.name
}".rstrip
)
end
"#{
{ false => 'terminated', nil => 'aborted' }[thread.status]
} Thread #{thread.native_thread_id} #{thread.name}".rstrip
"#{THREAD_STATE[thread.status] || thread.status} Thread #{
@thread_id[thread]
} #{thread.name}".rstrip
end

def _print_vars(kind, names)
Expand Down Expand Up @@ -547,7 +540,11 @@ def initialize(&block)

ARG_SIG = { rest: '*', keyrest: '**', block: '&' }.compare_by_identity.freeze
NO_NAME = { :* => 1, :** => 1, :& => 1 }.compare_by_identity.freeze
private_constant :ARG_SIG, :NO_NAME
THREAD_STATE = {
false => 'terminated',
nil => 'aborted'
}.compare_by_identity.freeze
private_constant :ARG_SIG, :NO_NAME, :THREAD_STATE

@trace = {}.compare_by_identity
@caller_locations = true
Expand Down Expand Up @@ -621,6 +618,12 @@ def initialize(&block)
end

@fiber_supported = !!(defined?(Fiber.current) && defined?(Fiber.storage))
@thread_id =
if defined?(Thread.current.native_thread_id)
lambda(&:native_thread_id)
else
lambda(&:__id__)
end

self.trace_calls = true
end

0 comments on commit 61d752c

Please sign in to comment.