our @EXPORT_OK = qw(now msg_more);
use warnings;
use 5.010_001;
+use Scalar::Util qw(blessed);
use PublicInbox::Syscall qw(:epoll);
use PublicInbox::Tmpfile;
$LoopTimeout, # timeout of event loop in milliseconds
$DoneInit, # if we've done the one-time module init yet
@Timers, # timers
+ $in_loop,
);
Reset();
my $q = $nextq;
$nextq = [];
for (@$q) {
- if (ref($_) eq 'CODE') {
- $_->();
- } else {
+ # we avoid "ref" on blessed refs to workaround a Perl 5.16.3 leak:
+ # https://rt.perl.org/Public/Bug/Display.html?id=114340
+ if (blessed($_)) {
$_->event_step;
+ } else {
+ $_->();
}
}
}
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: