]> git.ipfire.org Git - thirdparty/public-inbox.git/commitdiff
ds: get rid of SetLoopTimeout
authorEric Wong <e@80x24.org>
Tue, 17 Oct 2023 23:38:00 +0000 (23:38 +0000)
committerEric Wong <e@80x24.org>
Wed, 18 Oct 2023 20:50:31 +0000 (20:50 +0000)
It's not worth the code and memory to have a setter method we
never use outside of tests.

lib/PublicInbox/DS.pm
t/dir_idle.t
t/ds-leak.t
xt/mem-imapd-tls.t
xt/mem-nntpd-tls.t

index 9960937dcd2cf3dfd4517db7f62f43aa32c08884..6041c6b549e057091eca385ad38d71a5288c24b0 100644 (file)
@@ -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;
index 02759b543911bc3e4bcdf3ec54dcc17873647e3f..35c800f98b99aa83256db7ba410d5c22462f3e2f 100644 (file)
@@ -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 $!";
index eaca05b8f61c0385b36d35f666f5e4bee5a3e3c5..179997eba06718913e0f962b18e91c2bae01b21e 100644 (file)
@@ -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;
index 00199a9b620305a4cb05d52c0ca314c7268b070a..585810174be451acdc7de3c4e7d64f9fac3aa213 100644 (file)
@@ -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();
 }
index f9b98a6b35efe13ae37e239ac3942897810e5e38..ec639a8bff85a53e2cb1c56ca902e737947a847e 100644 (file)
@@ -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;