awaitpid($pid) if $$ == $ppid; # for non-event loop
}
-# use this if we have multiple readers reading curl or "pigz -dc"
-# and writing to the same store
-sub ipc_lock_init {
- my ($self, $f) = @_;
- $f // die 'BUG: no filename given';
- require PublicInbox::Lock;
- $self->{-ipc_lock} //= bless { lock_path => $f }, 'PublicInbox::Lock'
-}
-
sub _wait_return ($$) {
my ($r_res, $sub) = @_;
my $ret = _get_rec($r_res) // die "no response on $sub";
sub ipc_do {
my ($self, $sub, @args) = @_;
if (my $w_req = $self->{-ipc_req}) { # run in worker
- my $ipc_lock = $self->{-ipc_lock};
- my $lock = $ipc_lock ? $ipc_lock->lock_for_scope : undef;
if (defined(wantarray)) {
my $r_res = $self->{-ipc_res} or die 'no ipc_res';
_send_rec($w_req, [ wantarray, $sub, @args ]);
defined($pid) or BAIL_OUT 'no spawn, no test';
is($ipc->ipc_do('test_pid'), $pid, 'worker pid returned');
$test->('worker');
- $ipc->ipc_lock_init("$tmpdir/lock");
is($ipc->ipc_do('test_pid'), $pid, 'worker pid returned');
$ipc->ipc_worker_stop;
ok(!kill(0, $pid) && $!{ESRCH}, 'worker stopped');