From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on dcvr.yhbt.net X-Spam-Level: X-Spam-ASN: AS55 158.130.0.0/16 X-Spam-Status: No, score=-2.6 required=3.0 tests=BAYES_00,RCVD_IN_MSPIKE_BL, RCVD_IN_MSPIKE_ZBI,RCVD_IN_XBL,SPF_FAIL,SPF_HELO_FAIL shortcircuit=no autolearn=no autolearn_force=no version=3.4.0 Received: from 80x24.org (tor-exit-node.seas.upenn.edu [158.130.0.242]) by dcvr.yhbt.net (Postfix) with ESMTP id 9150220A93 for ; Sat, 7 Jan 2017 01:45:01 +0000 (UTC) From: Eric Wong To: meta@public-inbox.org Subject: [PATCH 1/9] qspawn: prepare to support runtime reloading of Limiter Date: Sat, 7 Jan 2017 01:44:44 +0000 Message-Id: <20170107014452.9657-2-e@80x24.org> In-Reply-To: <20170107014452.9657-1-e@80x24.org> References: <20170107014452.9657-1-e@80x24.org> List-Id: We may allow the {max} value of a limiter to be changed in the future, so lets start accounting for it before we spawn followup processes. --- lib/PublicInbox/Qspawn.pm | 11 ++++++++--- 1 file changed, 8 insertions(+), 3 deletions(-) diff --git a/lib/PublicInbox/Qspawn.pm b/lib/PublicInbox/Qspawn.pm index 697c55a..4950da2 100644 --- a/lib/PublicInbox/Qspawn.pm +++ b/lib/PublicInbox/Qspawn.pm @@ -31,14 +31,19 @@ sub _do_spawn { sub finish ($) { my ($self) = @_; my $limiter = $self->{limiter}; + my $running; if (delete $self->{rpipe}) { my $pid = delete $self->{pid}; $self->{err} = $pid == waitpid($pid, 0) ? $? : "PID:$pid still running?"; - $limiter->{running}--; + $running = --$limiter->{running}; } - if (my $next = shift @{$limiter->{run_queue}}) { - _do_spawn(@$next); + + # limiter->{max} may change dynamically + if (($running || $limiter->{running}) < $limiter->{max}) { + if (my $next = shift @{$limiter->{run_queue}}) { + _do_spawn(@$next); + } } $self->{err}; } -- EW