| 1 | package Test2::IPC; | ||||||||||||||||||||||||||||||||||
| 2 | 97 | ▶ | use strict; | ||||||||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||||||||
| 3 | 97 | ▶ | use warnings; | ||||||||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||||||||
| 4 | |||||||||||||||||||||||||||||||||||
| 5 | 97 | our $VERSION = '1.302226'; | |||||||||||||||||||||||||||||||||
| 6 | |||||||||||||||||||||||||||||||||||
| 7 | |||||||||||||||||||||||||||||||||||
| 8 | 97 | ▶ | use Test2::API::Instance; | ||||||||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||||||||
| 9 | 97 | ▶ | use Test2::Util qw/get_tid/; | ||||||||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||||||||
| 10 | 97 | ▶ | use Test2::API qw{ | ||||||||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||||||||
| 11 | test2_in_preload | ||||||||||||||||||||||||||||||||||
| 12 | test2_init_done | ||||||||||||||||||||||||||||||||||
| 13 | test2_ipc | ||||||||||||||||||||||||||||||||||
| 14 | test2_has_ipc | ||||||||||||||||||||||||||||||||||
| 15 | test2_ipc_enable_polling | ||||||||||||||||||||||||||||||||||
| 16 | test2_pid | ||||||||||||||||||||||||||||||||||
| 17 | test2_stack | ||||||||||||||||||||||||||||||||||
| 18 | test2_tid | ||||||||||||||||||||||||||||||||||
| 19 | context | ||||||||||||||||||||||||||||||||||
| 20 | 97 | }; | |||||||||||||||||||||||||||||||||
| 21 | |||||||||||||||||||||||||||||||||||
| 22 | # Make sure stuff is finalized before anyone tried to fork or start a new thread. | ||||||||||||||||||||||||||||||||||
| 23 | { | ||||||||||||||||||||||||||||||||||
| 24 | # Avoid warnings if things are loaded at run-time | ||||||||||||||||||||||||||||||||||
| 25 | 97 | ▶ | no warnings 'void'; | ||||||||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||||||||
| 26 | 97 | ▶ | INIT { | ||||||||||||||||||||||||||||||||
|
Subroutine
INIT: called CC=2 SCAR=7.0
| |||||||||||||||||||||||||||||||||||
| 27 | 97 | ▶ | use warnings 'void'; | ||||||||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||||||||
| 28 | 97 | ▶ | context()->release() unless test2_in_preload(); | ||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||
| 29 | } | ||||||||||||||||||||||||||||||||||
| 30 | } | ||||||||||||||||||||||||||||||||||
| 31 | |||||||||||||||||||||||||||||||||||
| 32 | 97 | ▶ | use Carp qw/confess/; | ||||||||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||||||||
| 33 | |||||||||||||||||||||||||||||||||||
| 34 | 97 | our @EXPORT_OK = qw/cull/; | |||||||||||||||||||||||||||||||||
| 35 | 97 | ▶ | BEGIN { require Exporter; our @ISA = qw(Exporter) } | ||||||||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||||||||
| 36 | |||||||||||||||||||||||||||||||||||
| 37 | 1 | ▶ | sub unimport { Test2::API::test2_ipc_disable() } | ||||||||||||||||||||||||||||||||
|
Subroutine
unimport: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||||||||
| 38 | |||||||||||||||||||||||||||||||||||
| 39 | 147 | ▶ | sub import { | ||||||||||||||||||||||||||||||||
|
Subroutine
import: called CC=6 SCAR=31.3
| |||||||||||||||||||||||||||||||||||
| 40 | 147 | ▶ | goto &Exporter::import if test2_has_ipc || !test2_init_done(); | ||||||||||||||||||||||||||||||||
|
Branch: 1 branch
Condition66%2/3
test2_has_ipc() or not test2_init_done()
MC/DC0%0/2
test2_has_ipc() or not test2_init_done()
test2_has_ipc()
not test2_init_done()
Truth table66%2/3
A or not(B)
A= test2_has_ipc()B= not test2_init_done()
| |||||||||||||||||||||||||||||||||||
| 41 | |||||||||||||||||||||||||||||||||||
| 42 | 0 | ▶ | confess "IPC is disabled" if Test2::API::test2_ipc_disabled(); | ||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||
| 43 | 0 | ▶ | confess "Cannot add IPC in a child process (" . test2_pid() . " vs $$)" if test2_pid() != $$; | ||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||
| 44 | 0 | ▶ | confess "Cannot add IPC in a child thread (" . test2_tid() . " vs " . get_tid() . ")" if test2_tid() != get_tid(); | ||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||
| 45 | |||||||||||||||||||||||||||||||||||
| 46 | 0 | Test2::API::_set_ipc(_make_ipc()); | |||||||||||||||||||||||||||||||||
| 47 | 0 | apply_ipc(test2_stack()); | |||||||||||||||||||||||||||||||||
| 48 | |||||||||||||||||||||||||||||||||||
| 49 | 0 | goto &Exporter::import; | |||||||||||||||||||||||||||||||||
| 50 | } | ||||||||||||||||||||||||||||||||||
| 51 | |||||||||||||||||||||||||||||||||||
| 52 | 0 | ▶ | sub _make_ipc { | ||||||||||||||||||||||||||||||||
|
Subroutine
_make_ipc: not called CC=2 SCAR=17.9
| |||||||||||||||||||||||||||||||||||
| 53 | # Find a driver | ||||||||||||||||||||||||||||||||||
| 54 | 0 | my ($driver) = Test2::API::test2_ipc_drivers(); | |||||||||||||||||||||||||||||||||
| 55 | 0 | ▶ | unless ($driver) { | ||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||
| 56 | 0 | require Test2::IPC::Driver::Files; | |||||||||||||||||||||||||||||||||
| 57 | 0 | $driver = 'Test2::IPC::Driver::Files'; | |||||||||||||||||||||||||||||||||
| 58 | } | ||||||||||||||||||||||||||||||||||
| 59 | |||||||||||||||||||||||||||||||||||
| 60 | 0 | return $driver->new(); | |||||||||||||||||||||||||||||||||
| 61 | } | ||||||||||||||||||||||||||||||||||
| 62 | |||||||||||||||||||||||||||||||||||
| 63 | 0 | ▶ | sub apply_ipc { | ||||||||||||||||||||||||||||||||
|
Subroutine
apply_ipc: not called CC=10 SCAR=47.0
Pod
undocumented
| |||||||||||||||||||||||||||||||||||
| 64 | 0 | my $stack = shift; | |||||||||||||||||||||||||||||||||
| 65 | |||||||||||||||||||||||||||||||||||
| 66 | 0 | my ($root) = @$stack; | |||||||||||||||||||||||||||||||||
| 67 | |||||||||||||||||||||||||||||||||||
| 68 | 0 | ▶ | return unless $root; | ||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||
| 69 | |||||||||||||||||||||||||||||||||||
| 70 | 0 | ▶ | confess "Cannot add IPC in a child process" if $root->pid != $$; | ||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||
| 71 | 0 | ▶ | confess "Cannot add IPC in a child thread" if $root->tid != get_tid(); | ||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||
| 72 | |||||||||||||||||||||||||||||||||||
| 73 | 0 | ▶ | my $ipc = $root->ipc || test2_ipc() || _make_ipc(); | ||||||||||||||||||||||||||||||||
|
Condition0%0/6
$root->ipc || test2_ipc() || _make_ipc()
$root->ipc or test2_ipc()
MC/DC0%0/3
$root->ipc || test2_ipc() || _make_ipc()
$root->ipc
test2_ipc()
_make_ipc()
Truth table0%0/4
A or B || C
A= $root->ipcB= test2_ipc()C= _make_ipc()
| |||||||||||||||||||||||||||||||||||
| 74 | |||||||||||||||||||||||||||||||||||
| 75 | # Add the IPC to all hubs | ||||||||||||||||||||||||||||||||||
| 76 | 0 | for my $hub (@$stack) { | |||||||||||||||||||||||||||||||||
| 77 | 0 | my $has = $hub->ipc; | |||||||||||||||||||||||||||||||||
| 78 | 0 | ▶ | confess "IPC Mismatch!" if $has && $has != $ipc; | ||||||||||||||||||||||||||||||||
|
Branch: 1 branch
Condition0%0/3
$has and $has != $ipc
MC/DC0%0/2
$has and $has != $ipc
$has
$has != $ipc
Truth table0%0/3
A and B
A= $hasB= $has != $ipc
| |||||||||||||||||||||||||||||||||||
| 79 | 0 | ▶ | next if $has; | ||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||
| 80 | 0 | $hub->set_ipc($ipc); | |||||||||||||||||||||||||||||||||
| 81 | 0 | $ipc->add_hub($hub->hid); | |||||||||||||||||||||||||||||||||
| 82 | } | ||||||||||||||||||||||||||||||||||
| 83 | |||||||||||||||||||||||||||||||||||
| 84 | 0 | test2_ipc_enable_polling(); | |||||||||||||||||||||||||||||||||
| 85 | |||||||||||||||||||||||||||||||||||
| 86 | 0 | return $ipc; | |||||||||||||||||||||||||||||||||
| 87 | } | ||||||||||||||||||||||||||||||||||
| 88 | |||||||||||||||||||||||||||||||||||
| 89 | 0 | ▶ | sub cull { | ||||||||||||||||||||||||||||||||
|
Subroutine
cull: not called CC=1 SCAR=6.9
Pod
documented
| |||||||||||||||||||||||||||||||||||
| 90 | 0 | my $ctx = context(); | |||||||||||||||||||||||||||||||||
| 91 | 0 | $ctx->hub->cull; | |||||||||||||||||||||||||||||||||
| 92 | 0 | $ctx->release; | |||||||||||||||||||||||||||||||||
| 93 | } | ||||||||||||||||||||||||||||||||||
| 94 | |||||||||||||||||||||||||||||||||||
| 95 | 97 | 1; | |||||||||||||||||||||||||||||||||
| 96 | |||||||||||||||||||||||||||||||||||
| 97 | __END__ | ||||||||||||||||||||||||||||||||||