line |
stmt |
bran |
cond |
sub |
pod |
time |
code |
1
|
|
|
|
|
|
|
## -*- Mode: CPerl -*- |
2
|
|
|
|
|
|
|
## File: DiaColloDB::threads.pm |
3
|
|
|
|
|
|
|
## Author: Bryan Jurish <moocow@cpan.org> |
4
|
|
|
|
|
|
|
## Descript: DiaColloDB: temporary data structures: use threads.pm or forks.pm |
5
|
|
|
|
|
|
|
|
6
|
|
|
|
|
|
|
package DiaColloDB::threads; |
7
|
2
|
|
|
2
|
|
14
|
use Config; |
|
2
|
|
|
|
|
6
|
|
|
2
|
|
|
|
|
98
|
|
8
|
2
|
|
|
2
|
|
10
|
use strict; |
|
2
|
|
|
|
|
4
|
|
|
2
|
|
|
|
|
364
|
|
9
|
|
|
|
|
|
|
|
10
|
|
|
|
|
|
|
our ($MODULE); |
11
|
|
|
|
|
|
|
BEGIN { |
12
|
|
|
|
|
|
|
#$MODULE = '' if ($^P); ##-- disable threads if running under debugger |
13
|
|
|
|
|
|
|
|
14
|
2
|
50
|
|
2
|
|
14
|
if (!defined($MODULE)) { |
15
|
|
|
|
|
|
|
##-- attempt to load thread support |
16
|
2
|
50
|
|
|
|
192
|
my $loadme = $Config{usethreads} ? 'threads' : 'forks'; |
17
|
|
|
|
|
|
|
|
18
|
2
|
50
|
|
|
|
12
|
if ($INC{"$loadme.pm"}) { |
19
|
|
|
|
|
|
|
##-- thread-support already loaded |
20
|
0
|
|
|
|
|
0
|
$MODULE = $loadme; |
21
|
|
|
|
|
|
|
} |
22
|
|
|
|
|
|
|
else { |
23
|
|
|
|
|
|
|
##-- no thread-support loaded yet (loading forks.pm also sets $INC{"threads.pm"}=>"/path/to/forks.pm") |
24
|
|
|
|
|
|
|
#print STDERR __PACKAGE__, ": attempting to load $module\n"; |
25
|
2
|
|
|
2
|
|
178
|
my $rc = eval "use $loadme; 1"; |
|
2
|
|
|
|
|
2284
|
|
|
1
|
|
|
|
|
437374
|
|
|
1
|
|
|
|
|
10
|
|
26
|
1
|
|
|
|
|
4
|
my $err = "$@"; |
27
|
1
|
50
|
33
|
|
|
20
|
$MODULE = ($rc && !$err) ? $loadme : ''; |
28
|
1
|
50
|
|
|
|
5
|
warn(__PACKAGE__, " Warning: failed to load thread-support via ${loadme}.pm: $err") if (!$MODULE); |
29
|
|
|
|
|
|
|
} |
30
|
1
|
|
50
|
|
|
147
|
$MODULE //= ''; |
31
|
|
|
|
|
|
|
} |
32
|
|
|
|
|
|
|
} |
33
|
|
|
|
|
|
|
|
34
|
|
|
|
|
|
|
sub import { |
35
|
3
|
50
|
|
3
|
|
18
|
if ($MODULE) { |
36
|
|
|
|
|
|
|
#my $that = shift; |
37
|
3
|
|
|
|
|
12
|
my $caller = caller; |
38
|
3
|
|
|
|
|
236
|
my $sub = eval qq{sub { package $caller; $MODULE->import(); } }; |
39
|
3
|
|
|
|
|
63
|
$sub->(@_); |
40
|
|
|
|
|
|
|
} |
41
|
|
|
|
|
|
|
} |
42
|
|
|
|
|
|
|
|
43
|
|
|
|
|
|
|
## $threadid = CLASS->tid() |
44
|
|
|
|
|
|
|
sub tid { |
45
|
0
|
0
|
|
0
|
0
|
|
return $MODULE ? threads->tid() : 0; |
46
|
|
|
|
|
|
|
} |
47
|
|
|
|
|
|
|
|
48
|
|
|
|
|
|
|
|
49
|
|
|
|
|
|
|
1; ##-- be happy |
50
|
|
|
|
|
|
|
|
51
|
|
|
|
|
|
|
__END__ |