* [PATCH 4/5] ds: simplify EventLoop implementation
2020-12-27 2:53 6% [PATCH 0/5] some yak shaving Eric Wong
@ 2020-12-27 2:53 7% ` Eric Wong
0 siblings, 0 replies; 2+ results
From: Eric Wong @ 2020-12-27 2:53 UTC (permalink / raw)
To: meta
More importantly, make it easier-to-find the sub by avoiding
runtime manipulation of subroutine names. There's no point in
avoiding a potential call to _InitPoller in EventLoop since
entering EventLoop is rare.
On the contrary, PublicInbox::DS->new is called often and this
change to avoid entering _InitPoller there may have more
benefits (which may still be unmeasurable).
---
lib/PublicInbox/DS.pm | 29 ++++++++---------------------
1 file changed, 8 insertions(+), 21 deletions(-)
diff --git a/lib/PublicInbox/DS.pm b/lib/PublicInbox/DS.pm
index a02b3bb7..12df5919 100644
--- a/lib/PublicInbox/DS.pm
+++ b/lib/PublicInbox/DS.pm
@@ -50,7 +50,6 @@ our (
$PostLoopCallback, # subref to call at the end of each loop, if defined (global)
$LoopTimeout, # timeout of event loop in milliseconds
- $DoneInit, # if we've done the one-time module init yet
@Timers, # timers
$in_loop,
);
@@ -75,12 +74,9 @@ sub Reset {
@Timers = ();
$PostLoopCallback = undef;
- $DoneInit = 0;
$_io = undef; # closes real $Epoll FD
$Epoll = undef; # may call DSKQXS::DESTROY
-
- *EventLoop = *FirstTimeEventLoop;
}
=head2 C<< CLASS->SetLoopTimeout( $timeout ) >>
@@ -137,14 +133,13 @@ sub set_cloexec ($) {
fcntl($_io, F_SETFD, $fl | FD_CLOEXEC);
}
+# caller sets return value to $Epoll
sub _InitPoller
{
- return if $DoneInit;
- $DoneInit = 1;
-
if (PublicInbox::Syscall::epoll_defined()) {
- $Epoll = epoll_create();
- set_cloexec($Epoll) if (defined($Epoll) && $Epoll >= 0);
+ my $fd = epoll_create();
+ set_cloexec($fd) if (defined($fd) && $fd >= 0);
+ $fd;
} else {
my $cls;
for (qw(DSKQXS DSPoll)) {
@@ -152,9 +147,8 @@ sub _InitPoller
last if eval "require $cls";
}
$cls->import(qw(epoll_ctl epoll_wait));
- $Epoll = $cls->new;
+ $cls->new;
}
- *EventLoop = *EpollEventLoop;
}
=head2 C<< CLASS->EventLoop() >>
@@ -163,13 +157,6 @@ Start processing IO events. In most daemon programs this never exits. See
C<PostLoopCallback> below for how to exit the loop.
=cut
-sub FirstTimeEventLoop {
- my $class = shift;
-
- _InitPoller();
-
- EventLoop($class);
-}
sub now () { clock_gettime(CLOCK_MONOTONIC) }
@@ -271,7 +258,8 @@ sub PostEventLoop () {
$PostLoopCallback ? $PostLoopCallback->(\%DescriptorMap) : 1;
}
-sub EpollEventLoop {
+sub EventLoop {
+ $Epoll //= _InitPoller();
local $in_loop = 1;
do {
my @events;
@@ -330,8 +318,7 @@ sub new {
$self->{sock} = $sock;
my $fd = fileno($sock);
- _InitPoller();
-
+ $Epoll //= _InitPoller();
retry:
if (epoll_ctl($Epoll, EPOLL_CTL_ADD, $fd, $ev)) {
if ($! == EINVAL && ($ev & EPOLLEXCLUSIVE)) {
^ permalink raw reply related [relevance 7%]
* [PATCH 0/5] some yak shaving
@ 2020-12-27 2:53 6% Eric Wong
2020-12-27 2:53 7% ` [PATCH 4/5] ds: simplify EventLoop implementation Eric Wong
0 siblings, 1 reply; 2+ results
From: Eric Wong @ 2020-12-27 2:53 UTC (permalink / raw)
To: meta
Some minor things to fix some small annoyances; I needed a break
from other areas of the code.
Eric Wong (5):
git: qx: avoid extra "local" for scalar context case
import: check for git->qx errors, clearer return values
check defined return value for localized slurp errors
ds: simplify EventLoop implementation
ds: flatten + reuse @events, epoll_wait style fixes
lib/PublicInbox/DS.pm | 49 ++++++++--------------------
lib/PublicInbox/DSKQXS.pm | 2 +-
lib/PublicInbox/DSPoll.pm | 3 +-
lib/PublicInbox/Gcf2.pm | 2 +-
lib/PublicInbox/Git.pm | 6 ++--
lib/PublicInbox/Import.pm | 9 +++---
lib/PublicInbox/Inbox.pm | 9 ++----
lib/PublicInbox/Syscall.pm | 66 +++++++++++++++++++++-----------------
script/public-inbox-edit | 3 +-
script/public-inbox-init | 6 +---
script/public-inbox-learn | 3 +-
script/public-inbox-purge | 2 +-
t/ds-poll.t | 28 ++++++++--------
t/epoll.t | 8 ++---
t/git.t | 5 +++
15 files changed, 92 insertions(+), 109 deletions(-)
^ permalink raw reply [relevance 6%]
Results 1-2 of 2 | reverse | options above
-- pct% links below jump to the message on this page, permalinks otherwise --
2020-12-27 2:53 6% [PATCH 0/5] some yak shaving Eric Wong
2020-12-27 2:53 7% ` [PATCH 4/5] ds: simplify EventLoop implementation Eric Wong
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).