user/dev discussion of public-inbox itself
 help / color / mirror / Atom feed
* [PATCH] git: introduce async_wait_all
@ 2020-10-17  8:04 Eric Wong
  0 siblings, 0 replies; only message in thread
From: Eric Wong @ 2020-10-17  8:04 UTC (permalink / raw)
  To: meta

->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        | 14 ++++++++++++--
 lib/PublicInbox/SearchIdx.pm  |  3 +--
 lib/PublicInbox/V2Writable.pm |  3 +--
 3 files changed, 14 insertions(+), 6 deletions(-)

diff --git a/lib/PublicInbox/Git.pm b/lib/PublicInbox/Git.pm
index e3a2bcb8..86343ac9 100644
--- a/lib/PublicInbox/Git.pm
+++ b/lib/PublicInbox/Git.pm
@@ -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));
diff --git a/lib/PublicInbox/SearchIdx.pm b/lib/PublicInbox/SearchIdx.pm
index 2c5c815f..2aec2b73 100644
--- a/lib/PublicInbox/SearchIdx.pm
+++ b/lib/PublicInbox/SearchIdx.pm
@@ -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;
diff --git a/lib/PublicInbox/V2Writable.pm b/lib/PublicInbox/V2Writable.pm
index 534cd7dc..c04f0c59 100644
--- a/lib/PublicInbox/V2Writable.pm
+++ b/lib/PublicInbox/V2Writable.pm
@@ -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});
 }
 

^ permalink raw reply	[flat|nested] only message in thread

only message in thread, other threads:[~2020-10-17  8:04 UTC | newest]

Thread overview: (only message) (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2020-10-17  8:04 [PATCH] git: introduce async_wait_all Eric Wong

user/dev discussion of public-inbox itself

This inbox may be cloned and mirrored by anyone:

	git clone --mirror http://public-inbox.org/meta
	git clone --mirror http://czquwvybam4bgbro.onion/meta
	git clone --mirror http://hjrcffqmbrq6wope.onion/meta
	git clone --mirror http://ou63pmih66umazou.onion/meta

	# If you have public-inbox 1.1+ installed, you may
	# initialize and index your mirror using the following commands:
	public-inbox-init -V1 meta meta/ http://public-inbox.org/meta \
		meta@public-inbox.org
	public-inbox-index meta

Example config snippet for mirrors.
Newsgroups are available over NNTP:
	nntp://news.public-inbox.org/inbox.comp.mail.public-inbox.meta
	nntp://ou63pmih66umazou.onion/inbox.comp.mail.public-inbox.meta
	nntp://czquwvybam4bgbro.onion/inbox.comp.mail.public-inbox.meta
	nntp://hjrcffqmbrq6wope.onion/inbox.comp.mail.public-inbox.meta
	nntp://news.gmane.io/gmane.mail.public-inbox.general
 note: .onion URLs require Tor: https://www.torproject.org/

code repositories for the project(s) associated with this inbox:

	https://80x24.org/public-inbox.git

AGPL code for this site: git clone https://public-inbox.org/public-inbox.git