| 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 | ▶ | use Config; | ||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||
| 8 | 2 | ▶ | use strict; | ||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||
| 9 | |||||||||||||||||||||||||||||
| 10 | 1 | our ($MODULE); | |||||||||||||||||||||||||||
| 11 | 2 | ▶ | BEGIN { | ||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=8 SCAR=23.4
| |||||||||||||||||||||||||||||
| 12 | #$MODULE = '' if ($^P); ##-- disable threads if running under debugger | ||||||||||||||||||||||||||||
| 13 | |||||||||||||||||||||||||||||
| 14 | 2 | ▶ | if (!defined($MODULE)) { | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 15 | ##-- attempt to load thread support | ||||||||||||||||||||||||||||
| 16 | 2 | ▶ | my $loadme = $Config{usethreads} ? 'threads' : 'forks'; | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 17 | |||||||||||||||||||||||||||||
| 18 | 2 | ▶ | if ($INC{"$loadme.pm"}) { | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 19 | ##-- thread-support already loaded | ||||||||||||||||||||||||||||
| 20 | 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 | ▶ | my $rc = eval "use $loadme; 1"; | ||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||
| 26 | 1 | my $err = "$@"; | |||||||||||||||||||||||||||
| 27 | 1 | ▶ | $MODULE = ($rc && !$err) ? $loadme : ''; | ||||||||||||||||||||||||||
|
Branch: 1 branch
Condition33%1/3
$rc and not $err
MC/DC0%0/2
$rc and not $err
$rc
not $err
Truth table33%1/3
A and not(B)
A= $rcB= not $err
| |||||||||||||||||||||||||||||
| 28 | 1 | ▶ | warn(__PACKAGE__, " Warning: failed to load thread-support via ${loadme}.pm: $err") if (!$MODULE); | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 29 | } | ||||||||||||||||||||||||||||
| 30 | 1 | ▶ | $MODULE //= ''; | ||||||||||||||||||||||||||
|
Condition50%1/2
$DiaColloDB::threads::MODULE //= ""
MC/DC0%0/1
$DiaColloDB::threads::MODULE //= ""
$DiaColloDB::threads::MODULE
Truth table50%1/2
A
A= $DiaColloDB::threads::MODULE
| |||||||||||||||||||||||||||||
| 31 | } | ||||||||||||||||||||||||||||
| 32 | } | ||||||||||||||||||||||||||||
| 33 | |||||||||||||||||||||||||||||
| 34 | 3 | ▶ | sub import { | ||||||||||||||||||||||||||
|
Subroutine
import: called CC=2 SCAR=7.0
| |||||||||||||||||||||||||||||
| 35 | 3 | ▶ | if ($MODULE) { | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 36 | #my $that = shift; | ||||||||||||||||||||||||||||
| 37 | 3 | my $caller = caller; | |||||||||||||||||||||||||||
| 38 | 3 | my $sub = eval qq{sub { package $caller; $MODULE->import(); } }; | |||||||||||||||||||||||||||
| 39 | 3 | $sub->(@_); | |||||||||||||||||||||||||||
| 40 | } | ||||||||||||||||||||||||||||
| 41 | } | ||||||||||||||||||||||||||||
| 42 | |||||||||||||||||||||||||||||
| 43 | ## $threadid = CLASS->tid() | ||||||||||||||||||||||||||||
| 44 | 0 | ▶ | sub tid { | ||||||||||||||||||||||||||
|
Subroutine
tid: not called CC=2 SCAR=17.9
Pod
undocumented
| |||||||||||||||||||||||||||||
| 45 | 0 | ▶ | return $MODULE ? threads->tid() : 0; | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 46 | } | ||||||||||||||||||||||||||||
| 47 | |||||||||||||||||||||||||||||
| 48 | |||||||||||||||||||||||||||||
| 49 | 1 | 1; ##-- be happy | |||||||||||||||||||||||||||
| 50 | |||||||||||||||||||||||||||||
| 51 | __END__ | ||||||||||||||||||||||||||||