ViewVC Help
View File | Revision Log | Show Annotations | Download File
/cvs/Coro/Coro/MakeMaker.pm
Revision: 1.86
Committed: Mon Mar 16 11:12:52 2020 UTC (4 years, 2 months ago) by root
Branch: MAIN
CVS Tags: rel-6_57, HEAD
Changes since 1.85: +1 -1 lines
Log Message:
*** empty log message ***

File Contents

# Content
1 package Coro::MakeMaker;
2
3 use common::sense;
4
5 use Config;
6 use base 'Exporter';
7
8 our $installsitearch;
9
10 our $VERSION = 6.57;
11 our @EXPORT_OK = qw(&coro_args $installsitearch);
12
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 Coro::MakeMaker - MakeMaker glue for the XS-level Coro API
44
45 =head1 SYNOPSIS
46
47 This allows you to control coroutines from C/XS.
48
49 =head1 DESCRIPTION
50
51 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
55 =head1 WARNING
56
57 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
62 =head1 HOW TO
63
64 =head2 Makefile.PL
65
66 use Coro::MakeMaker qw(coro_args);
67
68 # ... set up %args ...
69
70 WriteMakefile (coro_args (%args));
71
72 =head2 XS
73
74 #include "CoroAPI.h"
75
76 BOOT:
77 I_CORO_API ("YourModule");
78
79 =head2 API
80
81 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 You can also drop me a mail if you run into any trouble.
87
88 #define CORO_TRANSFER(prev,next) /* transfer from prev to next */
89 #define CORO_SCHEDULE /* like Coro::schedule */
90 #define CORO_CEDE /* like Coro::cede */
91 #define CORO_CEDE_NOTSELF /* like Coro::cede_notself */
92 #define CORO_READY(coro) /* like $coro->ready */
93 #define CORO_IS_READY(coro) /* like $coro->is_ready */
94 #define CORO_NREADY /* # of procs in ready queue */
95 #define CORO_CURRENT /* returns $Coro::current */
96 #define CORO_THROW /* exception pending? */
97 #define CORO_READYHOOK /* hook for event libs, see Coro::EV */
98
99 /* C-level coroutine struct, opaque, not used much */
100 struct coro;
101
102 /* used for schedule-like-function prepares */
103 struct coro_transfer_args
104 {
105 struct coro *prev, *next;
106 };
107
108 /* this is the per-perl-coro slf frame info */
109 struct CoroSLF
110 {
111 void (*prepare) (pTHX_ struct coro_transfer_args *ta); /* 0 means not yet initialised */
112 int (*check) (pTHX_ struct CoroSLF *frame);
113 void *data; /* for use by prepare/check/destroy */
114 void (*destroy) (pTHX_ struct CoroSLF *frame);
115 };
116
117 /* needs to fill in the *frame */
118 typedef void (*coro_slf_cb) (pTHX_ struct CoroSLF *frame, CV *cv, SV **arg, int items);
119
120 #define CORO_SV_STATE(coro) /* returns the internal struct coro * */
121 #define CORO_EXECUTE_SLF(cv,init,ax) /* execute a schedule-like function */
122 #define CORO_EXECUTE_SLF_XS(init) /* SLF in XS, see e.g. Coro::EV */
123
124 /* called on enter/leave */
125 typedef void (*coro_enterleave_hook) (pTHX_ void *arg);
126
127 #define CORO_ENTERLEAVE_HOOK(coro,enter,enter_arg,leave,leave_arg) /* install an XS-level enter/leave hook */
128 #define CORO_ENTERLEAVE_UNHOOK(coro,enter,leave) /* remove an XS-level enter/leave hook */
129 #define CORO_ENTERLEAVE_SCOPE_HOOK(enter,enter_arg,leave,leave_arg) /* install an XS-level enter/leave hook for the corrent scope */
130
131 =head1 AUTHOR/SUPPORT/CONTACT
132
133 Marc A. Lehmann <schmorp@schmorp.de>
134 http://software.schmorp.de/pkg/Coro.html
135
136 =cut