ViewVC Help
View File | Revision Log | Show Annotations | Download File
/cvs/Coro/Coro/CoroAPI.h
Revision: 1.28
Committed: Wed Jul 1 11:33:25 2009 UTC (14 years, 11 months ago) by root
Content type: text/plain
Branch: MAIN
CVS Tags: rel-5_151, rel-5_161, rel-5_371, rel-5_372, rel-5_22, rel-5_23, rel-5_24, rel-5_25, rel-5_162, rel-5_2, rel-5_37, rel-5_36, rel-5_17, rel-5_16
Changes since 1.27: +3 -0 lines
Log Message:
*** empty log message ***

File Contents

# User Rev Content
1 root 1.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 pcg 1.5 #ifndef pTHX_
9     # define pTHX_
10     # define aTHX_
11     # define pTHX
12     # define aTHX
13     #endif
14    
15 root 1.21 /* C-level coroutine struct, opaque, not used much */
16     struct coro;
17 root 1.1
18 root 1.21 /* used for schedule-like-function prepares */
19     struct coro_transfer_args
20     {
21     struct coro *prev, *next;
22 root 1.19 };
23    
24 root 1.22 /* 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 root 1.19 struct CoroSLF
28     {
29 root 1.23 void (*prepare) (pTHX_ struct coro_transfer_args *ta); /* 0 means not yet initialised */
30 root 1.22 int (*check) (pTHX_ struct CoroSLF *frame);
31     void *data; /* for use by prepare/check */
32 root 1.19 };
33    
34 root 1.22 /* needs to fill in the *frame */
35 root 1.24 typedef void (*coro_slf_cb) (pTHX_ struct CoroSLF *frame, CV *cv, SV **arg, int items);
36 root 1.22
37 root 1.10 /* private structure, always use the provided macros below */
38 root 1.19 struct CoroAPI
39     {
40 root 1.28 /* private */
41 root 1.1 I32 ver;
42 root 1.15 I32 rev;
43 root 1.19 #define CORO_API_VERSION 7
44     #define CORO_API_REVISION 0
45    
46 root 1.20 /* Coro */
47     int nready;
48     SV *current;
49 root 1.26 SV *except;
50 root 1.20 void (*readyhook) (void);
51    
52     void (*schedule) (pTHX);
53 root 1.27 void (*schedule_to) (pTHX_ SV *coro_sv);
54 root 1.19 int (*cede) (pTHX);
55     int (*cede_notself) (pTHX);
56     int (*ready) (pTHX_ SV *coro_sv);
57     int (*is_ready) (pTHX_ SV *coro_sv);
58 root 1.18
59 root 1.20 /* Coro::State */
60     void (*transfer) (pTHX_ SV *prev_sv, SV *next_sv); /* Coro::State */
61 root 1.22
62     /* SLF */
63 root 1.21 struct coro *(*sv_state) (pTHX_ SV *coro);
64 root 1.25 void (*execute_slf) (pTHX_ CV *cv, coro_slf_cb init_cb, I32 ax);
65 root 1.28
66     /* public */
67 root 1.22 /* for use as CoroSLF.prepare */
68 root 1.23 void (*prepare_nop) (pTHX_ struct coro_transfer_args *ta);
69     void (*prepare_schedule) (pTHX_ struct coro_transfer_args *ta);
70     void (*prepare_cede) (pTHX_ struct coro_transfer_args *ta);
71     void (*prepare_cede_notself) (pTHX_ struct coro_transfer_args *ta);
72 root 1.1 };
73    
74     static struct CoroAPI *GCoroAPI;
75    
76 root 1.11 /* public API macros */
77     #define CORO_TRANSFER(prev,next) GCoroAPI->transfer (aTHX_ (prev), (next))
78 root 1.22
79     #define CORO_SV_STATE(coro) GCoroAPI->sv_state (aTHX_ (coro))
80 root 1.25 #define CORO_EXECUTE_SLF(cv,init,ax) GCoroAPI->execute_slf (aTHX_ (cv), (init), (ax))
81     #define CORO_EXECUTE_SLF_XS(init) CORO_EXECUTE_SLF (cv, (init), ax)
82 root 1.22
83 root 1.19 #define CORO_SCHEDULE GCoroAPI->schedule (aTHX)
84     #define CORO_CEDE GCoroAPI->cede (aTHX)
85     #define CORO_CEDE_NOTSELF GCoroAPI->cede_notself (aTHX)
86     #define CORO_READY(coro) GCoroAPI->ready (aTHX_ coro)
87 root 1.11 #define CORO_IS_READY(coro) GCoroAPI->is_ready (coro)
88 root 1.26 #define CORO_NREADY (GCoroAPI->nready)
89     #define CORO_THROW (GCoroAPI->except)
90 root 1.22 #define CORO_CURRENT SvRV (GCoroAPI->current)
91 root 1.26 #define CORO_READYHOOK (GCoroAPI->readyhook)
92 root 1.21
93 root 1.17 #define I_CORO_API(YourName) \
94     STMT_START { \
95     SV *sv = perl_get_sv ("Coro::API", 0); \
96     if (!sv) croak ("Coro::API not found"); \
97     GCoroAPI = (struct CoroAPI*) SvIV (sv); \
98     if (GCoroAPI->ver != CORO_API_VERSION \
99     || GCoroAPI->rev < CORO_API_REVISION) \
100 root 1.16 croak ("Coro::API version mismatch (%d.%d vs. %d.%d) -- please recompile %s", \
101     GCoroAPI->ver, GCoroAPI->rev, CORO_API_VERSION, CORO_API_REVISION, YourName); \
102 root 1.1 } STMT_END
103    
104     #endif
105