From: Eric Wong <e@80x24.org>
To: meta@public-inbox.org
Subject: [PATCH 2/3] ds: cleanup fork + Reset support
Date: Wed, 4 Oct 2023 08:50:57 +0000 [thread overview]
Message-ID: <20231004085059.2115839-3-e@80x24.org> (raw)
In-Reply-To: <20231004085059.2115839-1-e@80x24.org>
We used to have many entries for %Stack, but nowadays it's just
the one used by next_tick, so just replace it a $cur_runq variable.
I'm reducing reliance on hash keys for things with global scope
to ensure typos can be detected (strict||v5.12 forces us to fix
uses of undeclared variables, but they can't detect typos in
hash keys.
---
lib/PublicInbox/DS.pm | 18 ++++++++----------
1 file changed, 8 insertions(+), 10 deletions(-)
diff --git a/lib/PublicInbox/DS.pm b/lib/PublicInbox/DS.pm
index e085a010..8f77b6ad 100644
--- a/lib/PublicInbox/DS.pm
+++ b/lib/PublicInbox/DS.pm
@@ -36,11 +36,11 @@ use Errno qw(EAGAIN EINVAL ECHILD);
use Carp qw(carp croak);
our @EXPORT_OK = qw(now msg_more awaitpid add_timer add_uniq_timer);
-my %Stack;
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 ]
+ $cur_runq, # only set inside next_tick
%DescriptorMap, # fd (num) -> PublicInbox::DS object
$Poller, # global Select, Epoll, DSPoll, or DSKQXS ref
@@ -78,14 +78,14 @@ sub Reset {
%UniqTimer = ();
@post_loop_do = ();
- # we may be iterating inside one of these on our stack
- my @q = delete @Stack{keys %Stack};
- for my $q (@q) { @$q = () }
+ # 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
$Poller = PublicInbox::Select->new;
- } while (@Timers || keys(%Stack) || $nextq || $AWAIT_PIDS ||
+ } while (@Timers || $nextq || $AWAIT_PIDS ||
$ToClose || keys(%DescriptorMap) ||
- @post_loop_do || keys(%UniqTimer));
+ @post_loop_do || keys(%UniqTimer) ||
+ scalar(@{$cur_runq // []})); # do not vivify cur_runq
$reap_armed = undef;
$LoopTimeout = -1; # no timeout by default
@@ -145,10 +145,9 @@ sub _InitPoller () {
sub now () { clock_gettime(CLOCK_MONOTONIC) }
sub next_tick () {
- my $q = $nextq or return;
+ local $cur_runq = $nextq or return;
$nextq = undef;
- $Stack{cur_runq} = $q;
- for my $obj (@$q) {
+ for my $obj (@$cur_runq) {
# 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($obj)) {
@@ -157,7 +156,6 @@ sub next_tick () {
$obj->();
}
}
- delete $Stack{cur_runq};
}
# runs timers and returns milliseconds for next one, or next event loop
next prev parent reply other threads:[~2023-10-04 8:50 UTC|newest]
Thread overview: 4+ messages / expand[flat|nested] mbox.gz Atom feed top
2023-10-04 8:50 [PATCH 0/3] ds fix and cleanups Eric Wong
2023-10-04 8:50 ` [PATCH 1/3] ds: Reset: replace Poller object early Eric Wong
2023-10-04 8:50 ` Eric Wong [this message]
2023-10-04 8:50 ` [PATCH 3/3] ds: make %AWAIT_PIDS a hash, not hashref Eric Wong
Reply instructions:
You may reply publicly to this message via plain-text email
using any one of the following methods:
* Save the following mbox file, import it into your mail client,
and reply-to-all from there: mbox
Avoid top-posting and favor interleaved quoting:
https://en.wikipedia.org/wiki/Posting_style#Interleaved_style
List information: https://public-inbox.org/README
* Reply using the --to, --cc, and --in-reply-to
switches of git-send-email(1):
git send-email \
--in-reply-to=20231004085059.2115839-3-e@80x24.org \
--to=e@80x24.org \
--cc=meta@public-inbox.org \
/path/to/YOUR_REPLY
https://kernel.org/pub/software/scm/git/docs/git-send-email.html
* If your mail client supports setting the In-Reply-To header
via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line
before the message body.
Code repositories for project(s) associated with this public inbox
https://80x24.org/public-inbox.git
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for read-only IMAP folder(s) and NNTP newsgroup(s).