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