use Carp qw(croak confess carp);
require File::Spec;
-my $nextq = []; # queue for next_tick
-my $WaitPids = []; # list of [ pid, callback, callback_arg ]
+my $nextq; # queue for next_tick
+my $WaitPids; # list of [ pid, callback, callback_arg ]
my $reap_timer;
our (
%DescriptorMap, # fd (num) -> PublicInbox::DS object
$LoopTimeout, # timeout of event loop in milliseconds
$DoneInit, # if we've done the one-time module init yet
@Timers, # timers
+ $in_loop,
);
Reset();
=cut
sub Reset {
%DescriptorMap = ();
+ $nextq = [];
$WaitPids = [];
$reap_timer = undef;
@ToClose = ();
sub enqueue_reap ($) { push @$nextq, \&reap_pids };
sub EpollEventLoop {
- local $SIG{CHLD} = \&enqueue_reap;
+ local $in_loop = 1;
while (1) {
my @events;
my $i;
# must be called with eval, PublicInbox::DS may not be loaded (see t/qspawn.t)
sub dwaitpid ($$$) {
my ($pid, $cb, $arg) = @_;
- my $chld = $SIG{CHLD};
- if (defined($chld) && $chld eq \&enqueue_reap) {
+ if ($in_loop) {
push @$WaitPids, [ $pid, $cb, $arg ];
# We could've just missed our SIGCHLD, cover it, here: