user/dev discussion of public-inbox itself
 help / color / mirror / code / Atom feed
From: Eric Wong <e@80x24.org>
To: meta@public-inbox.org
Subject: [PATCH 15/30] ds: get rid of SetLoopTimeout
Date: Tue, 17 Oct 2023 23:38:00 +0000	[thread overview]
Message-ID: <20231017233815.1637932-16-e@80x24.org> (raw)
In-Reply-To: <20231017233815.1637932-1-e@80x24.org>

It's not worth the code and memory to have a setter method we
never use outside of tests.
---
 lib/PublicInbox/DS.pm | 24 +++++++-----------------
 t/dir_idle.t          |  2 +-
 t/ds-leak.t           |  4 ++--
 xt/mem-imapd-tls.t    |  8 ++++----
 xt/mem-nntpd-tls.t    |  8 ++++----
 5 files changed, 18 insertions(+), 28 deletions(-)

diff --git a/lib/PublicInbox/DS.pm b/lib/PublicInbox/DS.pm
index 9960937d..6041c6b5 100644
--- a/lib/PublicInbox/DS.pm
+++ b/lib/PublicInbox/DS.pm
@@ -47,7 +47,7 @@ our (%AWAIT_PIDS, # pid => [ $callback, @args ]
 
      @post_loop_do,              # subref + args to call at the end of each loop
 
-     $LoopTimeout,               # timeout of event loop in milliseconds
+     $loop_timeout,               # timeout of event loop in milliseconds
      @Timers,                    # timers
      %UniqTimer,
      $in_loop,
@@ -89,20 +89,10 @@ sub Reset {
 		scalar(@{$cur_runq // []})); # do not vivify cur_runq
 
 	$reap_armed = undef;
-	$LoopTimeout = -1;  # no timeout by default
+	$loop_timeout = -1;  # no timeout by default
 	$Poller = PublicInbox::Select->new;
 }
 
-=head2 C<< CLASS->SetLoopTimeout( $timeout ) >>
-
-Set the loop timeout for the event loop to some value in milliseconds.
-
-A timeout of 0 (zero) means poll forever. A timeout of -1 means poll and return
-immediately.
-
-=cut
-sub SetLoopTimeout { $LoopTimeout = $_[1] + 0 }
-
 sub _add_named_timer {
 	my ($name, $secs, $coderef, @args) = @_;
 	my $fire_time = now() + $secs;
@@ -163,7 +153,7 @@ sub next_tick () {
 sub RunTimers {
 	next_tick();
 
-	return (($nextq || $ToClose) ? 0 : $LoopTimeout) unless @Timers;
+	return (($nextq || $ToClose) ? 0 : $loop_timeout) unless @Timers;
 
 	my $now = now();
 
@@ -177,16 +167,16 @@ sub RunTimers {
 	# timers may enqueue into nextq:
 	return 0 if ($nextq || $ToClose);
 
-	return $LoopTimeout unless @Timers;
+	return $loop_timeout unless @Timers;
 
 	# convert time to an even number of milliseconds, adding 1
 	# extra, otherwise floating point fun can occur and we'll
 	# call RunTimers like 20-30 times, each returning a timeout
 	# of 0.0000212 seconds
-	my $timeout = int(($Timers[0][0] - $now) * 1000) + 1;
+	my $t = int(($Timers[0][0] - $now) * 1000) + 1;
 
 	# -1 is an infinite timeout, so prefer a real timeout
-	($LoopTimeout < 0 || $LoopTimeout >= $timeout) ? $timeout : $LoopTimeout
+	($loop_timeout < 0 || $loop_timeout >= $t) ? $t : $loop_timeout
 }
 
 sub sig_setmask { sigprocmask(SIG_SETMASK, @_) or die "sigprocmask: $!" }
@@ -305,7 +295,7 @@ sub event_loop (;$$) {
 		sig_setmask($oldset) if $oldset;
 		sigprocmask(SIG_UNBLOCK, unblockset($sig)) or
 			die "SIG_UNBLOCK: $!";
-		PublicInbox::DS->SetLoopTimeout(1000);
+		$loop_timeout = 1000;
 	}
 	$_[0] = $sigfd = $sig = undef; # $_[0] == sig
 	local $in_loop = 1;
diff --git a/t/dir_idle.t b/t/dir_idle.t
index 02759b54..35c800f9 100644
--- a/t/dir_idle.t
+++ b/t/dir_idle.t
@@ -11,7 +11,7 @@ my @x;
 my $cb = sub { push @x, \@_ };
 my $di = PublicInbox::DirIdle->new($cb);
 $di->add_watches(["$tmpdir/a", "$tmpdir/c"], 1);
-PublicInbox::DS->SetLoopTimeout(1000);
+$PublicInbox::DS::loop_timeout = 1000;
 my $end = 3 + now;
 local @PublicInbox::DS::post_loop_do = (sub { scalar(@x) == 0 && now < $end });
 rmdir("$tmpdir/a/b") or xbail "rmdir $!";
diff --git a/t/ds-leak.t b/t/ds-leak.t
index eaca05b8..179997eb 100644
--- a/t/ds-leak.t
+++ b/t/ds-leak.t
@@ -11,7 +11,7 @@ if ('close-on-exec for epoll and kqueue') {
 	my $pid;
 	my $evfd_re = qr/(?:kqueue|eventpoll)/i;
 
-	PublicInbox::DS->SetLoopTimeout(0);
+	$PublicInbox::DS::loop_timeout = 0;
 	local @PublicInbox::DS::post_loop_do = (sub { 0 });
 
 	# make sure execve closes if we're using fork()
@@ -54,7 +54,7 @@ SKIP: {
 	}
 	my $cb = sub {};
 	for my $i (0..$n) {
-		PublicInbox::DS->SetLoopTimeout(0);
+		$PublicInbox::DS::loop_timeout = 0;
 		local @PublicInbox::DS::post_loop_do = ($cb);
 		PublicInbox::DS::event_loop();
 		PublicInbox::DS->Reset;
diff --git a/xt/mem-imapd-tls.t b/xt/mem-imapd-tls.t
index 00199a9b..58581017 100644
--- a/xt/mem-imapd-tls.t
+++ b/xt/mem-imapd-tls.t
@@ -81,7 +81,7 @@ sub once { 0 }; # stops event loop
 
 # setup the event loop so that it exits at every step
 # while we're still doing connect(2)
-PublicInbox::DS->SetLoopTimeout(0);
+$PublicInbox::DS::loop_timeout = 0;
 local @PublicInbox::DS::post_loop_do = (\&once);
 my $pid = $td->{pid};
 if ($^O eq 'linux' && open(my $f, '<', "/proc/$pid/status")) {
@@ -100,21 +100,21 @@ foreach my $n (1..$nfd) {
 	# try not to overflow the listen() backlog:
 	if (!($n % 128) && $DONE != $n) {
 		diag("nr: ($n) $DONE/$nfd");
-		PublicInbox::DS->SetLoopTimeout(-1);
+		$PublicInbox::DS::loop_timeout = -1;
 		local @PublicInbox::DS::post_loop_do = (sub { $DONE != $n });
 
 		# clear the backlog:
 		PublicInbox::DS::event_loop();
 
 		# resume looping
-		PublicInbox::DS->SetLoopTimeout(0);
+		$PublicInbox::DS::loop_timeout = 0;
 	}
 }
 
 # run the event loop normally, now:
 diag "done?: @".time." $DONE/$nfd";
 if ($DONE != $nfd) {
-	PublicInbox::DS->SetLoopTimeout(-1);
+	$PublicInbox::DS::loop_timeout = -1;
 	local @PublicInbox::DS::post_loop_do = (sub { $DONE != $nfd });
 	PublicInbox::DS::event_loop();
 }
diff --git a/xt/mem-nntpd-tls.t b/xt/mem-nntpd-tls.t
index f9b98a6b..ec639a8b 100644
--- a/xt/mem-nntpd-tls.t
+++ b/xt/mem-nntpd-tls.t
@@ -104,7 +104,7 @@ sub once { 0 }; # stops event loop
 
 # setup the event loop so that it exits at every step
 # while we're still doing connect(2)
-PublicInbox::DS->SetLoopTimeout(0);
+$PublicInbox::DS::loop_timeout = 0;
 local @PublicInbox::DS::post_loop_do = (\&once);
 
 foreach my $n (1..$nfd) {
@@ -119,14 +119,14 @@ foreach my $n (1..$nfd) {
 	# try not to overflow the listen() backlog:
 	if (!($n % 128) && $n != $DONE) {
 		diag("nr: ($n) $DONE/$nfd");
-		PublicInbox::DS->SetLoopTimeout(-1);
+		$PublicInbox::DS::loop_timeout = -1;
 		@PublicInbox::DS::post_loop_do = (sub { $DONE != $n });
 
 		# clear the backlog:
 		PublicInbox::DS::event_loop();
 
 		# resume looping
-		PublicInbox::DS->SetLoopTimeout(0);
+		$PublicInbox::DS::loop_timeout = 0;
 		@PublicInbox::DS::post_loop_do = (\&once);
 	}
 }
@@ -140,7 +140,7 @@ $dump_rss->();
 
 # run the event loop normally, now:
 if ($DONE != $nfd) {
-	PublicInbox::DS->SetLoopTimeout(-1);
+	$PublicInbox::DS::loop_timeout = -1;
 	@PublicInbox::DS::post_loop_do = (sub {
 		diag "done: ".time." $DONE";
 		$DONE != $nfd;

  parent reply	other threads:[~2023-10-17 23:38 UTC|newest]

Thread overview: 32+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2023-10-17 23:37 [PATCH 00/30] autodie-ification and code simplifications Eric Wong
2023-10-17 23:37 ` [PATCH 01/30] lei_mirror: start converting to autodie Eric Wong
2023-10-17 23:37 ` [PATCH 02/30] lei_mirror: autodie most `close' calls Eric Wong
2023-10-17 23:37 ` [PATCH 03/30] lei_mirror: use autodie for most `open' calls Eric Wong
2023-10-17 23:37 ` [PATCH 04/30] git: introduce read_all function Eric Wong
2023-10-17 23:37 ` [PATCH 05/30] import: use read_all to detect short reads Eric Wong
2023-10-17 23:37 ` [PATCH 06/30] lei_mirror: use read_all Eric Wong
2023-10-17 23:37 ` [PATCH 07/30] use read_all in more places to improve safety Eric Wong
2023-10-17 23:37 ` [PATCH 08/30] xap_helper*: use autodie in more places Eric Wong
2023-10-17 23:37 ` [PATCH 09/30] xap_helper: die more easily in both implementations Eric Wong
2023-10-17 23:37 ` [PATCH 10/30] xap_helper: simplify SIGTERM exit checks Eric Wong
2023-10-17 23:37 ` [PATCH 11/30] xap_helper: autodie for getsockopt Eric Wong
2023-10-17 23:37 ` [PATCH 12/30] xap_client: autodie for pipe and socketpair Eric Wong
2023-10-17 23:37 ` [PATCH 13/30] xt/git-http-backend: remove Net::HTTP usage Eric Wong
2023-10-17 23:37 ` [PATCH 14/30] ds: introduce and use do_fork helper Eric Wong
2023-10-17 23:38 ` Eric Wong [this message]
2023-10-17 23:38 ` [PATCH 16/30] cindex: drop some unused functions Eric Wong
2023-10-17 23:38 ` [PATCH 17/30] syscall: common $F_SETPIPE_SZ definition Eric Wong
2023-10-17 23:38 ` [PATCH 18/30] t/lei-up: additional diagnostics for match failures Eric Wong
2023-10-17 23:38 ` [PATCH 19/30] test_common: use autodie and read_all where possible Eric Wong
2023-10-17 23:38 ` [PATCH 20/30] test_common: only hide TCP port in messages Eric Wong
2023-10-17 23:38 ` [PATCH 21/30] test_common: use $cwdfh for every run_script command Eric Wong
2023-10-17 23:38 ` [PATCH 22/30] init: drop extraneous `+' Eric Wong
2023-10-17 23:38 ` [PATCH 23/30] init: use autodie to reduce distractions Eric Wong
2023-10-17 23:38 ` [PATCH 24/30] xt/mem-imapd-tls: remove unused/broken epoll imports Eric Wong
2023-10-17 23:38 ` [PATCH 25/30] xt/mem-imapd-tls: reduce FDs for lsof use Eric Wong
2023-10-17 23:38 ` [PATCH 26/30] lei: use autodie where appropriate Eric Wong
2023-10-17 23:38 ` [PATCH 27/30] lei_auth: update comments and use v5.12 Eric Wong
2023-10-17 23:38 ` [PATCH 28/30] lei_config: drop redundant open check Eric Wong
2023-10-17 23:38 ` [PATCH 29/30] convert: use read_all to simplify error checks Eric Wong
2023-10-17 23:38 ` [PATCH 30/30] idx_stack: use autodie + read_all Eric Wong
2023-10-19  1:14 ` [PATCH 31/30] lei: simplify startq/au_done wakeup notifications 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=20231017233815.1637932-16-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).