Skip to content

Commit

Permalink
Simplify Kernel signals method using Signal values
Browse files Browse the repository at this point in the history
The Kernel signals method previously had a lot of logic for determining
signal values on the host system and backends. Now that that logic is
encapsulated into the getsignals ops, this method can be greatly
simplified.
  • Loading branch information
jstuder-gh committed Jun 8, 2018
1 parent 398c270 commit d7ea2f7
Showing 1 changed file with 13 additions and 31 deletions.
44 changes: 13 additions & 31 deletions src/core/Kernel.pm6
Expand Up @@ -102,47 +102,29 @@ class Kernel does Systemic {
}

has @!signals; # Signal
#?if jvm
method signals (Kernel:D:) {
@!signals //= [2, 9]
}
#?endif
has $!signals-setup-lock = Lock.new;
#?if moar
has $!signals-setup = False;
has $!signals-setup = False;

method signals (Kernel:D:) {
unless $!signals-setup {
$!signals-setup-lock.protect: {
unless $!signals-setup {
my @names;
if self.name eq 'win32' {
# These are the ones libuv emulates on Windows.
@names = flat "", <INT BREAK HUP WINCH>;
} else {
if self.name eq 'openbsd' {
# otherwise it uses a shell buildin
@names = flat "", qx!/bin/kill -l!.words;
}
else {
@names = flat "", qx/kill -l/.words;
}
@names.splice(1,1) if @names[1] eq "0"; # Ubuntu fudge
@names.=map({.uc}) if $*KERNEL.name eq 'dragonfly';
}

for Signal.^enum_value_list -> $signal {
my $name = substr($signal.key,3);
if @names.first( * eq $name, :k ) -> $index {
@!signals[$index] = $signal;
}
}
$!signals-setup = True;
nqp::stmts(
( my \arr = nqp::list(Nil) ),
( my int $els = 32 ),
( my int $i = 1 ),
nqp::while(
nqp::islt_i($i, $els),
nqp::bindpos(arr, $i, Signal($i) // Nil),
$i = nqp::add_i($i, 1),
),
@!signals = |arr,
)
}
}
}
@!signals
}
#?endif

has %!signals-by-Str;
has $!signals-by-Str-setup = False;
Expand Down

0 comments on commit d7ea2f7

Please sign in to comment.