1 |
root |
1.1 |
package Coro::MakeMaker; |
2 |
|
|
|
3 |
root |
1.33 |
use common::sense; |
4 |
root |
1.2 |
|
5 |
root |
1.1 |
use Config; |
6 |
|
|
use base 'Exporter'; |
7 |
|
|
|
8 |
root |
1.33 |
our $installsitearch; |
9 |
|
|
|
10 |
root |
1.54 |
our $VERSION = "6.10"; |
11 |
root |
1.33 |
our @EXPORT_OK = qw(&coro_args $installsitearch); |
12 |
root |
1.1 |
|
13 |
|
|
my %opt; |
14 |
|
|
|
15 |
|
|
for my $opt (split /:+/, $ENV{PERL_MM_OPT}) { |
16 |
|
|
my ($k,$v) = split /=/, $opt; |
17 |
|
|
$opt{$k} = $v; |
18 |
|
|
} |
19 |
|
|
|
20 |
|
|
my $extra = $Config{sitearch}; |
21 |
|
|
|
22 |
|
|
$extra =~ s/$Config{prefix}/$opt{PREFIX}/ if |
23 |
|
|
exists $opt{PREFIX}; |
24 |
|
|
|
25 |
|
|
for my $d ($extra, @INC) { |
26 |
|
|
if (-e "$d/Coro/CoroAPI.h") { |
27 |
|
|
$installsitearch = $d; |
28 |
|
|
last; |
29 |
|
|
} |
30 |
|
|
} |
31 |
|
|
|
32 |
|
|
sub coro_args { |
33 |
|
|
my %arg = @_; |
34 |
|
|
$arg{INC} .= " -I$installsitearch/Coro"; |
35 |
|
|
%arg; |
36 |
|
|
} |
37 |
|
|
|
38 |
|
|
1; |
39 |
|
|
__END__ |
40 |
|
|
|
41 |
|
|
=head1 NAME |
42 |
|
|
|
43 |
root |
1.19 |
Coro::MakeMaker - MakeMaker glue for the XS-level Coro API |
44 |
root |
1.1 |
|
45 |
|
|
=head1 SYNOPSIS |
46 |
|
|
|
47 |
root |
1.19 |
This allows you to control coroutines from C/XS. |
48 |
root |
1.1 |
|
49 |
|
|
=head1 DESCRIPTION |
50 |
|
|
|
51 |
root |
1.19 |
For optimal performance, hook into Coro at the C-level. You'll need to |
52 |
|
|
make changes to your C<Makefile.PL> and add code to your C<xs> / C<c> |
53 |
|
|
file(s). |
54 |
root |
1.1 |
|
55 |
|
|
=head1 WARNING |
56 |
|
|
|
57 |
root |
1.19 |
When you hook in at the C-level you can get a I<huge> performance gain, |
58 |
|
|
but you also reduce the chances that your code will work unmodified with |
59 |
|
|
newer versions of C<perl> or C<Coro>. This may or may not be a problem. |
60 |
|
|
Just be aware, and set your expectations accordingly. |
61 |
root |
1.1 |
|
62 |
|
|
=head1 HOW TO |
63 |
|
|
|
64 |
|
|
=head2 Makefile.PL |
65 |
|
|
|
66 |
|
|
use Coro::MakeMaker qw(coro_args); |
67 |
|
|
|
68 |
|
|
# ... set up %args ... |
69 |
|
|
|
70 |
root |
1.27 |
WriteMakefile (coro_args (%args)); |
71 |
root |
1.1 |
|
72 |
|
|
=head2 XS |
73 |
|
|
|
74 |
|
|
#include "CoroAPI.h" |
75 |
|
|
|
76 |
|
|
BOOT: |
77 |
root |
1.27 |
I_CORO_API ("YourModule"); |
78 |
root |
1.1 |
|
79 |
root |
1.5 |
=head2 API |
80 |
root |
1.1 |
|
81 |
root |
1.27 |
This is just a small overview - read the Coro/CoroAPI.h header file in |
82 |
|
|
the distribution, and check the examples in F<EV/> and F<Event/*>, or |
83 |
|
|
as a more real-world example, the Deliantra game server (which uses |
84 |
|
|
Coro::MakeMaker). |
85 |
|
|
|
86 |
root |
1.7 |
#define CORO_TRANSFER(prev,next) /* transfer from prev to next */ |
87 |
root |
1.5 |
#define CORO_SCHEDULE /* like Coro::schedule */ |
88 |
|
|
#define CORO_CEDE /* like Coro::cede */ |
89 |
root |
1.7 |
#define CORO_CEDE_NOTSELF /* like Coro::cede_notself */ |
90 |
root |
1.5 |
#define CORO_READY(coro) /* like $coro->ready */ |
91 |
root |
1.6 |
#define CORO_IS_READY(coro) /* like $coro->is_ready */ |
92 |
|
|
#define CORO_NREADY /* # of procs in ready queue */ |
93 |
root |
1.5 |
#define CORO_CURRENT /* returns $Coro::current */ |
94 |
root |
1.27 |
#define CORO_THROW /* exception pending? */ |
95 |
|
|
#define CORO_READYHOOK /* hook for event libs, see Coro::EV */ |
96 |
|
|
|
97 |
|
|
#define CORO_SV_STATE(coro) /* returns the internal struct coro * */ |
98 |
|
|
#define CORO_EXECUTE_SLF(cv,init,ax) /* execute a schedule-like function */ |
99 |
|
|
#define CORO_EXECUTE_SLF_XS(init) /* SLF in XS, see e.g. Coro::EV */ |
100 |
root |
1.1 |
|
101 |
|
|
=cut |