| 1 |
package Coro::MakeMaker; |
| 2 |
|
| 3 |
BEGIN { eval { require warnings } && warnings->unimport ("uninitialized") } |
| 4 |
|
| 5 |
use Config; |
| 6 |
use base 'Exporter'; |
| 7 |
|
| 8 |
@EXPORT_OK = qw(&coro_args $installsitearch); |
| 9 |
|
| 10 |
my %opt; |
| 11 |
|
| 12 |
for my $opt (split /:+/, $ENV{PERL_MM_OPT}) { |
| 13 |
my ($k,$v) = split /=/, $opt; |
| 14 |
$opt{$k} = $v; |
| 15 |
} |
| 16 |
|
| 17 |
my $extra = $Config{sitearch}; |
| 18 |
|
| 19 |
$extra =~ s/$Config{prefix}/$opt{PREFIX}/ if |
| 20 |
exists $opt{PREFIX}; |
| 21 |
|
| 22 |
for my $d ($extra, @INC) { |
| 23 |
if (-e "$d/Coro/CoroAPI.h") { |
| 24 |
$installsitearch = $d; |
| 25 |
last; |
| 26 |
} |
| 27 |
} |
| 28 |
|
| 29 |
sub coro_args { |
| 30 |
my %arg = @_; |
| 31 |
$arg{INC} .= " -I$installsitearch/Coro"; |
| 32 |
%arg; |
| 33 |
} |
| 34 |
|
| 35 |
1; |
| 36 |
__END__ |
| 37 |
|
| 38 |
=head1 NAME |
| 39 |
|
| 40 |
Coro::MakeMaker - MakeMaker glue for the C-level Coro API |
| 41 |
|
| 42 |
=head1 SYNOPSIS |
| 43 |
|
| 44 |
This allows you to control coroutines from C level. |
| 45 |
|
| 46 |
=head1 DESCRIPTION |
| 47 |
|
| 48 |
For optimal performance, hook into Coro at the C-level. You'll need |
| 49 |
to make changes to your C<Makefile.PL> and add code to your C<xs> / |
| 50 |
C<c> file(s). |
| 51 |
|
| 52 |
=head1 WARNING |
| 53 |
|
| 54 |
When you hook in at the C-level you get a I<huge> performance gain, |
| 55 |
but you also reduce the chances that your code will work unmodified |
| 56 |
with newer versions of C<perl> or C<Coro>. This may or may not be a |
| 57 |
problem. Just be aware, and set your expectations accordingly. |
| 58 |
|
| 59 |
=head1 HOW TO |
| 60 |
|
| 61 |
=head2 Makefile.PL |
| 62 |
|
| 63 |
use Coro::MakeMaker qw(coro_args); |
| 64 |
|
| 65 |
# ... set up %args ... |
| 66 |
|
| 67 |
WriteMakefile(coro_args(%args)); |
| 68 |
|
| 69 |
=head2 XS |
| 70 |
|
| 71 |
#include "CoroAPI.h" |
| 72 |
|
| 73 |
BOOT: |
| 74 |
I_CORO_API("YourModule"); |
| 75 |
|
| 76 |
=head2 API |
| 77 |
|
| 78 |
/* perl-related */ |
| 79 |
#define TRANSFER_SAVE_DEFAV /* save @_ */ |
| 80 |
#define TRANSFER_SAVE_DEFSV /* save $_ */ |
| 81 |
#define TRANSFER_SAVE_ERRSV /* save $@ */ |
| 82 |
/* c-related */ |
| 83 |
#define TRANSFER_SAVE_CCTXT /* save C context (stack) */ |
| 84 |
#define TRANSFER_LAZY_STACK /* try to allocate stacks lazily */ |
| 85 |
|
| 86 |
#define TRANSFER_SAVE_ALL (TRANSFER_SAVE_DEFAV | TRANSFER_SAVE_DEFSV \ |
| 87 |
| TRANSFER_SAVE_ERRSV | TRANSFER_SAVE_CCTXT) |
| 88 |
|
| 89 |
#define CORO_TRANSFER(prev,next,flags) /* transfer from prev to next */ |
| 90 |
#define CORO_SCHEDULE /* like Coro::schedule */ |
| 91 |
#define CORO_CEDE /* like Coro::cede */ |
| 92 |
#define CORO_READY(coro) /* like $coro->ready */ |
| 93 |
#define CORO_NREADY /* # of procs in runqueue */ |
| 94 |
#define CORO_CURRENT /* returns $Coro::current */ |
| 95 |
|
| 96 |
=cut |