From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.6 (2021-04-09) on dcvr.yhbt.net X-Spam-Level: X-Spam-ASN: X-Spam-Status: No, score=-4.2 required=3.0 tests=ALL_TRUSTED,BAYES_00, DKIM_SIGNED,DKIM_VALID,DKIM_VALID_AU,DKIM_VALID_EF shortcircuit=no autolearn=ham autolearn_force=no version=3.4.6 Received: from localhost (dcvr.yhbt.net [127.0.0.1]) by dcvr.yhbt.net (Postfix) with ESMTP id C5F861F487 for ; Wed, 4 Oct 2023 08:50:59 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=80x24.org; s=selector1; t=1696409459; bh=nQ5iRLXSHf3DUaT86r9ePHXhmeJvmZhXUQV1PLGb+vc=; h=From:To:Subject:Date:In-Reply-To:References:From; b=ScTx6bk7xHxxcviqxHI0y+YlhveavEtJP9sGl9BQB56/1UbnX3j81jRAd3hUEAL8N vl/3IUC+XRHgXGXD0EnGkepsiMszgIqePF9WYVcLjzKRFRWyp9WhOmljvPKFXrVaL1 pFLR8OE5HIzblrt4Kpa22UBTyLBOFGitw53wBkL8= From: Eric Wong To: meta@public-inbox.org Subject: [PATCH 3/3] ds: make %AWAIT_PIDS a hash, not hashref Date: Wed, 4 Oct 2023 08:50:58 +0000 Message-ID: <20231004085059.2115839-4-e@80x24.org> In-Reply-To: <20231004085059.2115839-1-e@80x24.org> References: <20231004085059.2115839-1-e@80x24.org> MIME-Version: 1.0 Content-Transfer-Encoding: 8bit List-Id: This is more persistent than some of the others and we don't swap it on use (unlike $nextq or $ToClose). In other words, it's helpful for communicating its lifetime expectancy is close to %DescriptorMap and not like to queue-type things such as $ToClose. --- lib/PublicInbox/DS.pm | 15 ++++++++------- lib/PublicInbox/LEI.pm | 2 +- 2 files changed, 9 insertions(+), 8 deletions(-) diff --git a/lib/PublicInbox/DS.pm b/lib/PublicInbox/DS.pm index 8f77b6ad..26cc83f0 100644 --- a/lib/PublicInbox/DS.pm +++ b/lib/PublicInbox/DS.pm @@ -39,7 +39,7 @@ our @EXPORT_OK = qw(now msg_more awaitpid add_timer add_uniq_timer); my $nextq; # queue for next_tick my $reap_armed; my $ToClose; # sockets to close when event loop is done -our ($AWAIT_PIDS, # pid => [ $callback, @args ] +our (%AWAIT_PIDS, # pid => [ $callback, @args ] $cur_runq, # only set inside next_tick %DescriptorMap, # fd (num) -> PublicInbox::DS object $Poller, # global Select, Epoll, DSPoll, or DSKQXS ref @@ -80,9 +80,10 @@ sub Reset { # we may be called from an *atfork_child inside next_tick: @$cur_runq = () if $cur_runq; - $AWAIT_PIDS = $nextq = $ToClose = undef; # may call ep_del + $nextq = $ToClose = undef; # may call ep_del + %AWAIT_PIDS = (); $Poller = PublicInbox::Select->new; - } while (@Timers || $nextq || $AWAIT_PIDS || + } while (@Timers || $nextq || keys(%AWAIT_PIDS) || $ToClose || keys(%DescriptorMap) || @post_loop_do || keys(%UniqTimer) || scalar(@{$cur_runq // []})); # do not vivify cur_runq @@ -218,7 +219,7 @@ sub reap_pids { $reap_armed = undef; while (1) { my $pid = waitpid(-1, WNOHANG) or return; - if (defined(my $cb_args = delete $AWAIT_PIDS->{$pid})) { + if (defined(my $cb_args = delete $AWAIT_PIDS{$pid})) { await_cb($pid, @$cb_args) if $cb_args; } elsif ($pid == -1 && $! == ECHILD) { return requeue(\&dflush); # force @post_loop_do to run @@ -719,17 +720,17 @@ sub long_response ($$;@) { sub awaitpid { my ($pid, @cb_args) = @_; # @cb_args = ($cb, @args), $cb may be undef - $AWAIT_PIDS->{$pid} = \@cb_args if @cb_args; + $AWAIT_PIDS{$pid} = \@cb_args if @cb_args; # provide synchronous API if (defined(wantarray) || (!$in_loop && !@cb_args)) { my $ret = waitpid($pid, 0); if ($ret == $pid) { - my $cb_args = delete $AWAIT_PIDS->{$pid}; + my $cb_args = delete $AWAIT_PIDS{$pid}; @cb_args = @$cb_args if !@cb_args && $cb_args; await_cb($pid, @cb_args); } else { carp "waitpid($pid) => $ret ($!)"; - delete $AWAIT_PIDS->{$pid}; + delete $AWAIT_PIDS{$pid}; } return $ret; } elsif ($in_loop) { # We could've just missed our SIGCHLD, cover it, here: diff --git a/lib/PublicInbox/LEI.pm b/lib/PublicInbox/LEI.pm index 5f3147bf..e300f0a4 100644 --- a/lib/PublicInbox/LEI.pm +++ b/lib/PublicInbox/LEI.pm @@ -1302,7 +1302,7 @@ sub can_stay_alive { # PublicInbox::DS::post_loop_do cb } }; # returns true: continue, false: stop - $n + scalar(keys(%$PublicInbox::DS::AWAIT_PIDS)); + $n + scalar(keys(%PublicInbox::DS::AWAIT_PIDS)); } # lei(1) calls this when it can't connect