| 1 | package threads;
|
|---|
| 2 |
|
|---|
| 3 | use 5.008;
|
|---|
| 4 | use strict;
|
|---|
| 5 | use warnings;
|
|---|
| 6 | use Config;
|
|---|
| 7 |
|
|---|
| 8 | BEGIN {
|
|---|
| 9 | unless ($Config{useithreads}) {
|
|---|
| 10 | my @caller = caller(2);
|
|---|
| 11 | die <<EOF;
|
|---|
| 12 | $caller[1] line $caller[2]:
|
|---|
| 13 |
|
|---|
| 14 | This Perl hasn't been configured and built properly for the threads
|
|---|
| 15 | module to work. (The 'useithreads' configuration option hasn't been used.)
|
|---|
| 16 |
|
|---|
| 17 | Having threads support requires all of Perl and all of the XS modules in
|
|---|
| 18 | the Perl installation to be rebuilt, it is not just a question of adding
|
|---|
| 19 | the threads module. (In other words, threaded and non-threaded Perls
|
|---|
| 20 | are binary incompatible.)
|
|---|
| 21 |
|
|---|
| 22 | If you want to the use the threads module, please contact the people
|
|---|
| 23 | who built your Perl.
|
|---|
| 24 |
|
|---|
| 25 | Cannot continue, aborting.
|
|---|
| 26 | EOF
|
|---|
| 27 | }
|
|---|
| 28 | }
|
|---|
| 29 |
|
|---|
| 30 | use overload
|
|---|
| 31 | '==' => \&equal,
|
|---|
| 32 | 'fallback' => 1;
|
|---|
| 33 |
|
|---|
| 34 | BEGIN {
|
|---|
| 35 | warn "Warning, threads::shared has already been loaded. ".
|
|---|
| 36 | "To enable shared variables for these modules 'use threads' ".
|
|---|
| 37 | "must be called before any of those modules are loaded\n"
|
|---|
| 38 | if($threads::shared::threads_shared);
|
|---|
| 39 | }
|
|---|
| 40 |
|
|---|
| 41 | require Exporter;
|
|---|
| 42 | require DynaLoader;
|
|---|
| 43 |
|
|---|
| 44 | our @ISA = qw(Exporter DynaLoader);
|
|---|
| 45 |
|
|---|
| 46 | our %EXPORT_TAGS = ( all => [qw(yield)]);
|
|---|
| 47 |
|
|---|
| 48 | our @EXPORT_OK = ( @{ $EXPORT_TAGS{'all'} } );
|
|---|
| 49 |
|
|---|
| 50 | our @EXPORT = qw(
|
|---|
| 51 | async
|
|---|
| 52 | );
|
|---|
| 53 | our $VERSION = '1.07';
|
|---|
| 54 |
|
|---|
| 55 |
|
|---|
| 56 | # || 0 to ensure compatibility with previous versions
|
|---|
| 57 | sub equal { ($_[0]->tid == $_[1]->tid) || 0 }
|
|---|
| 58 |
|
|---|
| 59 | # use "goto" trick to avoid pad problems from 5.8.1 (fixed in 5.8.2)
|
|---|
| 60 | # should also be faster
|
|---|
| 61 | sub async (&;@) { unshift @_,'threads'; goto &new }
|
|---|
| 62 |
|
|---|
| 63 | sub object {
|
|---|
| 64 | return undef unless @_ > 1;
|
|---|
| 65 | foreach (threads->list) {
|
|---|
| 66 | return $_ if $_->tid == $_[1];
|
|---|
| 67 | }
|
|---|
| 68 | return undef;
|
|---|
| 69 | }
|
|---|
| 70 |
|
|---|
| 71 | $threads::threads = 1;
|
|---|
| 72 |
|
|---|
| 73 | bootstrap threads $VERSION;
|
|---|
| 74 |
|
|---|
| 75 | # why document 'new' then use 'create' in the tests!
|
|---|
| 76 | *create = \&new;
|
|---|
| 77 |
|
|---|
| 78 | # Preloaded methods go here.
|
|---|
| 79 |
|
|---|
|
|---|