ViewVC Help
View File | Revision Log | Show Annotations | Download File
/cvs/Coro/Coro/CoroAPI.h
Revision: 1.27
Committed: Thu Nov 20 06:28:52 2008 UTC (15 years, 7 months ago) by root
Content type: text/plain
Branch: MAIN
CVS Tags: rel-5_1, rel-5_0, rel-6_13, rel-5_11, rel-5_12, rel-5_15, rel-5_14, rel-5_132, rel-5_131
Changes since 1.26: +1 -0 lines
Log Message:
cede_to/schedule_to

File Contents

# Content
1 #ifndef CORO_API_H
2 #define CORO_API_H
3
4 #include "EXTERN.h"
5 #include "perl.h"
6 #include "XSUB.h"
7
8 #ifndef pTHX_
9 # define pTHX_
10 # define aTHX_
11 # define pTHX
12 # define aTHX
13 #endif
14
15 /* C-level coroutine struct, opaque, not used much */
16 struct coro;
17
18 /* used for schedule-like-function prepares */
19 struct coro_transfer_args
20 {
21 struct coro *prev, *next;
22 };
23
24 /* this is the per-perl-coro slf frame info */
25 /* it is treated like other "global" interpreter data */
26 /* and unfortunately is copied around, so keep it small */
27 struct CoroSLF
28 {
29 void (*prepare) (pTHX_ struct coro_transfer_args *ta); /* 0 means not yet initialised */
30 int (*check) (pTHX_ struct CoroSLF *frame);
31 void *data; /* for use by prepare/check */
32 };
33
34 /* needs to fill in the *frame */
35 typedef void (*coro_slf_cb) (pTHX_ struct CoroSLF *frame, CV *cv, SV **arg, int items);
36
37 /* private structure, always use the provided macros below */
38 struct CoroAPI
39 {
40 I32 ver;
41 I32 rev;
42 #define CORO_API_VERSION 7
43 #define CORO_API_REVISION 0
44
45 /* Coro */
46 int nready;
47 SV *current;
48 SV *except;
49 void (*readyhook) (void);
50
51 void (*schedule) (pTHX);
52 void (*schedule_to) (pTHX_ SV *coro_sv);
53 int (*cede) (pTHX);
54 int (*cede_notself) (pTHX);
55 int (*ready) (pTHX_ SV *coro_sv);
56 int (*is_ready) (pTHX_ SV *coro_sv);
57
58 /* Coro::State */
59 void (*transfer) (pTHX_ SV *prev_sv, SV *next_sv); /* Coro::State */
60
61 /* SLF */
62 struct coro *(*sv_state) (pTHX_ SV *coro);
63 void (*execute_slf) (pTHX_ CV *cv, coro_slf_cb init_cb, I32 ax);
64 /* for use as CoroSLF.prepare */
65 void (*prepare_nop) (pTHX_ struct coro_transfer_args *ta);
66 void (*prepare_schedule) (pTHX_ struct coro_transfer_args *ta);
67 void (*prepare_cede) (pTHX_ struct coro_transfer_args *ta);
68 void (*prepare_cede_notself) (pTHX_ struct coro_transfer_args *ta);
69 };
70
71 static struct CoroAPI *GCoroAPI;
72
73 /* public API macros */
74 #define CORO_TRANSFER(prev,next) GCoroAPI->transfer (aTHX_ (prev), (next))
75
76 #define CORO_SV_STATE(coro) GCoroAPI->sv_state (aTHX_ (coro))
77 #define CORO_EXECUTE_SLF(cv,init,ax) GCoroAPI->execute_slf (aTHX_ (cv), (init), (ax))
78 #define CORO_EXECUTE_SLF_XS(init) CORO_EXECUTE_SLF (cv, (init), ax)
79
80 #define CORO_SCHEDULE GCoroAPI->schedule (aTHX)
81 #define CORO_CEDE GCoroAPI->cede (aTHX)
82 #define CORO_CEDE_NOTSELF GCoroAPI->cede_notself (aTHX)
83 #define CORO_READY(coro) GCoroAPI->ready (aTHX_ coro)
84 #define CORO_IS_READY(coro) GCoroAPI->is_ready (coro)
85 #define CORO_NREADY (GCoroAPI->nready)
86 #define CORO_THROW (GCoroAPI->except)
87 #define CORO_CURRENT SvRV (GCoroAPI->current)
88 #define CORO_READYHOOK (GCoroAPI->readyhook)
89
90 #define I_CORO_API(YourName) \
91 STMT_START { \
92 SV *sv = perl_get_sv ("Coro::API", 0); \
93 if (!sv) croak ("Coro::API not found"); \
94 GCoroAPI = (struct CoroAPI*) SvIV (sv); \
95 if (GCoroAPI->ver != CORO_API_VERSION \
96 || GCoroAPI->rev < CORO_API_REVISION) \
97 croak ("Coro::API version mismatch (%d.%d vs. %d.%d) -- please recompile %s", \
98 GCoroAPI->ver, GCoroAPI->rev, CORO_API_VERSION, CORO_API_REVISION, YourName); \
99 } STMT_END
100
101 #endif
102