From: Eric Wong Date: Wed, 25 Oct 2023 00:29:44 +0000 (+0000) Subject: cindex: use timer for inits X-Git-Url: http://git.ipfire.org/cgi-bin/gitweb.cgi?a=commitdiff_plain;h=c125385d752833853ca48100312f4522d2b5087d;p=thirdparty%2Fpublic-inbox.git cindex: use timer for inits We'll need to be in the event loop to use run_await in parallel, so we can't start processes outside of it. This change isn't ideal, but it likely keeps the rest of our (hotter) code simpler. --- diff --git a/lib/PublicInbox/CodeSearchIdx.pm b/lib/PublicInbox/CodeSearchIdx.pm index 122bd4d49..b5ba03eaf 100644 --- a/lib/PublicInbox/CodeSearchIdx.pm +++ b/lib/PublicInbox/CodeSearchIdx.pm @@ -1105,6 +1105,15 @@ sub show_roots { # for diagnostics } } +sub do_inits { # called via PublicInbox::DS::add_timer + my ($self) = @_; + init_prune($self); + init_associate_postfork($self); + scan_git_dirs($self) if $self->{-opt}->{scan} // 1; + my $max = $TODO{associate} ? max($LIVE_JOBS, $NPROC) : $LIVE_JOBS; + index_next($self) for (1..$max); +} + sub cidx_run { # main entry point my ($self) = @_; my $restore_umask = prep_umask($self); @@ -1183,18 +1192,14 @@ sub cidx_run { # main entry point local $NPROC = PublicInbox::IPC::detect_nproc(); local $LIVE_JOBS = $self->{-opt}->{jobs} || $NPROC || 2; local @RDONLY_XDB = $self->xdb_shards_flat; - init_prune($self); - init_associate_postfork($self); - scan_git_dirs($self) if $self->{-opt}->{scan} // 1; - my $max = $TODO{associate} ? max($LIVE_JOBS, $NPROC) : $LIVE_JOBS; - index_next($self) for (1..$max); + PublicInbox::DS::add_timer(0, \&do_inits, $self); # FreeBSD ignores/discards SIGCHLD while signals are blocked and # EVFILT_SIGNAL is inactive, so we pretend we have a SIGCHLD pending PublicInbox::DS::enqueue_reap(); local @PublicInbox::DS::post_loop_do = (\&shards_active); - PublicInbox::DS::event_loop($MY_SIG, $SIGSET) if shards_active(); + PublicInbox::DS::event_loop($MY_SIG, $SIGSET); PublicInbox::DS->Reset; $self->lock_release(!!$NCHANGE); show_roots($self) if $self->{-opt}->{'show-roots'} # for diagnostics