]> Sergey Matveev's repositories - public-inbox.git/commitdiff
git: introduce async_wait_all
authorEric Wong <e@80x24.org>
Sat, 17 Oct 2020 08:04:24 +0000 (08:04 +0000)
committerEric Wong <e@80x24.org>
Sat, 17 Oct 2020 19:52:50 +0000 (19:52 +0000)
->cat_async and ->check_async may trigger each other (in future
callers) while waiting, so we need a unified method to ensure
both complete.  This doesn't affect current code, but allows us
to slightly simplify existing callers.

lib/PublicInbox/Git.pm
lib/PublicInbox/SearchIdx.pm
lib/PublicInbox/V2Writable.pm

index e3a2bcb8df8f43d5c3e421852ded73dde2c9a9e2..86343ac9e5a7d9b92c4ee15d79ee7c8c787735d4 100644 (file)
@@ -352,13 +352,23 @@ sub qx {
        <$fh>
 }
 
+# check_async and cat_async may trigger the other, so ensure they're
+# both completely done by using this:
+sub async_wait_all ($) {
+       my ($self) = @_;
+       while (scalar(@{$self->{inflight_c} // []}) ||
+                       scalar(@{$self->{inflight} // []})) {
+               $self->check_async_wait;
+               $self->cat_async_wait;
+       }
+}
+
 # returns true if there are pending "git cat-file" processes
 sub cleanup {
        my ($self) = @_;
        local $in_cleanup = 1;
        delete $self->{async_cat};
-       check_async_wait($self);
-       cat_async_wait($self);
+       async_wait_all($self);
        delete $self->{inflight};
        delete $self->{inflight_c};
        _destroy($self, qw(cat_rbuf in out pid));
index 2c5c815f605755da79e5d551b088331b6bee5e86..2aec2b73f70c6aef31f049ea92d5275cd4151e26 100644 (file)
@@ -587,8 +587,7 @@ sub check_size { # check_async cb for -index --max-size=...
 
 sub v1_checkpoint ($$;$) {
        my ($self, $sync, $stk) = @_;
-       $self->{ibx}->git->check_async_wait;
-       $self->{ibx}->git->cat_async_wait;
+       $self->{ibx}->git->async_wait_all;
 
        # latest_cmt may be undef
        my $newest = $stk ? $stk->{latest_cmt} : undef;
index 534cd7dcd8913869a8cfa36a53a021d29ac9bf7c..c04f0c5951495754da74061c79456ac14b9c8f8e 100644 (file)
@@ -1228,8 +1228,7 @@ sub index_epoch ($$$) {
                        reindex_checkpoint($self, $sync);
                }
        }
-       $all->check_async_wait;
-       $all->cat_async_wait;
+       $all->async_wait_all;
        update_last_commit($self, $git, $i, $stk->{latest_cmt});
 }