line |
stmt |
bran |
cond |
sub |
pod |
time |
code |
1
|
|
|
|
|
|
|
package Test2::IPC; |
2
|
26
|
|
|
26
|
|
12441
|
use strict; |
|
26
|
|
|
|
|
141
|
|
|
26
|
|
|
|
|
738
|
|
3
|
26
|
|
|
26
|
|
134
|
use warnings; |
|
26
|
|
|
|
|
42
|
|
|
26
|
|
|
|
|
983
|
|
4
|
|
|
|
|
|
|
|
5
|
|
|
|
|
|
|
our $VERSION = '1.302180'; |
6
|
|
|
|
|
|
|
|
7
|
|
|
|
|
|
|
|
8
|
26
|
|
|
26
|
|
9606
|
use Test2::API::Instance; |
|
26
|
|
|
|
|
66
|
|
|
26
|
|
|
|
|
143
|
|
9
|
26
|
|
|
26
|
|
182
|
use Test2::Util qw/get_tid/; |
|
26
|
|
|
|
|
60
|
|
|
26
|
|
|
|
|
1596
|
|
10
|
26
|
|
|
|
|
3101
|
use Test2::API qw{ |
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
|
26
|
|
|
26
|
|
12735
|
}; |
|
26
|
|
|
|
|
94
|
|
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
|
26
|
|
|
26
|
|
191
|
no warnings 'void'; |
|
26
|
|
|
|
|
58
|
|
|
26
|
|
|
|
|
1154
|
|
26
|
|
|
|
|
|
|
INIT { |
27
|
26
|
|
|
26
|
|
156
|
use warnings 'void'; |
|
26
|
|
|
|
|
69
|
|
|
26
|
|
|
|
|
2082
|
|
28
|
26
|
50
|
|
26
|
|
135
|
context()->release() unless test2_in_preload(); |
29
|
|
|
|
|
|
|
} |
30
|
|
|
|
|
|
|
} |
31
|
|
|
|
|
|
|
|
32
|
26
|
|
|
26
|
|
183
|
use Carp qw/confess/; |
|
26
|
|
|
|
|
57
|
|
|
26
|
|
|
|
|
1872
|
|
33
|
|
|
|
|
|
|
|
34
|
|
|
|
|
|
|
our @EXPORT_OK = qw/cull/; |
35
|
26
|
|
|
26
|
|
166
|
BEGIN { require Exporter; our @ISA = qw(Exporter) } |
|
26
|
|
|
|
|
11545
|
|
36
|
|
|
|
|
|
|
|
37
|
1
|
|
|
1
|
|
11
|
sub unimport { Test2::API::test2_ipc_disable() } |
38
|
|
|
|
|
|
|
|
39
|
|
|
|
|
|
|
sub import { |
40
|
26
|
50
|
66
|
26
|
|
305
|
goto &Exporter::import if test2_has_ipc || !test2_init_done(); |
41
|
|
|
|
|
|
|
|
42
|
0
|
0
|
|
|
|
|
confess "IPC is disabled" if Test2::API::test2_ipc_disabled(); |
43
|
0
|
0
|
|
|
|
|
confess "Cannot add IPC in a child process (" . test2_pid() . " vs $$)" if test2_pid() != $$; |
44
|
0
|
0
|
|
|
|
|
confess "Cannot add IPC in a child thread (" . test2_tid() . " vs " . get_tid() . ")" if test2_tid() != get_tid(); |
45
|
|
|
|
|
|
|
|
46
|
0
|
|
|
|
|
|
Test2::API::_set_ipc(_make_ipc()); |
47
|
0
|
|
|
|
|
|
apply_ipc(test2_stack()); |
48
|
|
|
|
|
|
|
|
49
|
0
|
|
|
|
|
|
goto &Exporter::import; |
50
|
|
|
|
|
|
|
} |
51
|
|
|
|
|
|
|
|
52
|
|
|
|
|
|
|
sub _make_ipc { |
53
|
|
|
|
|
|
|
# Find a driver |
54
|
0
|
|
|
0
|
|
|
my ($driver) = Test2::API::test2_ipc_drivers(); |
55
|
0
|
0
|
|
|
|
|
unless ($driver) { |
56
|
0
|
|
|
|
|
|
require Test2::IPC::Driver::Files; |
57
|
0
|
|
|
|
|
|
$driver = 'Test2::IPC::Driver::Files'; |
58
|
|
|
|
|
|
|
} |
59
|
|
|
|
|
|
|
|
60
|
0
|
|
|
|
|
|
return $driver->new(); |
61
|
|
|
|
|
|
|
} |
62
|
|
|
|
|
|
|
|
63
|
|
|
|
|
|
|
sub apply_ipc { |
64
|
0
|
|
|
0
|
0
|
|
my $stack = shift; |
65
|
|
|
|
|
|
|
|
66
|
0
|
|
|
|
|
|
my ($root) = @$stack; |
67
|
|
|
|
|
|
|
|
68
|
0
|
0
|
|
|
|
|
return unless $root; |
69
|
|
|
|
|
|
|
|
70
|
0
|
0
|
|
|
|
|
confess "Cannot add IPC in a child process" if $root->pid != $$; |
71
|
0
|
0
|
|
|
|
|
confess "Cannot add IPC in a child thread" if $root->tid != get_tid(); |
72
|
|
|
|
|
|
|
|
73
|
0
|
|
0
|
|
|
|
my $ipc = $root->ipc || test2_ipc() || _make_ipc(); |
74
|
|
|
|
|
|
|
|
75
|
|
|
|
|
|
|
# Add the IPC to all hubs |
76
|
0
|
|
|
|
|
|
for my $hub (@$stack) { |
77
|
0
|
|
|
|
|
|
my $has = $hub->ipc; |
78
|
0
|
0
|
0
|
|
|
|
confess "IPC Mismatch!" if $has && $has != $ipc; |
79
|
0
|
0
|
|
|
|
|
next if $has; |
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
|
|
|
|
|
|
|
sub cull { |
90
|
0
|
|
|
0
|
1
|
|
my $ctx = context(); |
91
|
0
|
|
|
|
|
|
$ctx->hub->cull; |
92
|
0
|
|
|
|
|
|
$ctx->release; |
93
|
|
|
|
|
|
|
} |
94
|
|
|
|
|
|
|
|
95
|
|
|
|
|
|
|
1; |
96
|
|
|
|
|
|
|
|
97
|
|
|
|
|
|
|
__END__ |