ViewVC Help
View File | Revision Log | Show Annotations | Download File
/cvs/Coro/Coro/CoroAPI.h
Revision: 1.26
Committed: Tue Nov 18 11:04:42 2008 UTC (15 years, 6 months ago) by root
Content type: text/plain
Branch: MAIN
Changes since 1.25: +4 -2 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.1 I32 ver;
41 root 1.15 I32 rev;
42 root 1.19 #define CORO_API_VERSION 7
43     #define CORO_API_REVISION 0
44    
45 root 1.20 /* Coro */
46     int nready;
47     SV *current;
48 root 1.26 SV *except;
49 root 1.20 void (*readyhook) (void);
50    
51     void (*schedule) (pTHX);
52 root 1.19 int (*cede) (pTHX);
53     int (*cede_notself) (pTHX);
54     int (*ready) (pTHX_ SV *coro_sv);
55     int (*is_ready) (pTHX_ SV *coro_sv);
56 root 1.18
57 root 1.20 /* Coro::State */
58     void (*transfer) (pTHX_ SV *prev_sv, SV *next_sv); /* Coro::State */
59 root 1.22
60     /* SLF */
61 root 1.21 struct coro *(*sv_state) (pTHX_ SV *coro);
62 root 1.25 void (*execute_slf) (pTHX_ CV *cv, coro_slf_cb init_cb, I32 ax);
63 root 1.22 /* for use as CoroSLF.prepare */
64 root 1.23 void (*prepare_nop) (pTHX_ struct coro_transfer_args *ta);
65     void (*prepare_schedule) (pTHX_ struct coro_transfer_args *ta);
66     void (*prepare_cede) (pTHX_ struct coro_transfer_args *ta);
67     void (*prepare_cede_notself) (pTHX_ struct coro_transfer_args *ta);
68 root 1.1 };
69    
70     static struct CoroAPI *GCoroAPI;
71    
72 root 1.11 /* public API macros */
73     #define CORO_TRANSFER(prev,next) GCoroAPI->transfer (aTHX_ (prev), (next))
74 root 1.22
75     #define CORO_SV_STATE(coro) GCoroAPI->sv_state (aTHX_ (coro))
76 root 1.25 #define CORO_EXECUTE_SLF(cv,init,ax) GCoroAPI->execute_slf (aTHX_ (cv), (init), (ax))
77     #define CORO_EXECUTE_SLF_XS(init) CORO_EXECUTE_SLF (cv, (init), ax)
78 root 1.22
79 root 1.19 #define CORO_SCHEDULE GCoroAPI->schedule (aTHX)
80     #define CORO_CEDE GCoroAPI->cede (aTHX)
81     #define CORO_CEDE_NOTSELF GCoroAPI->cede_notself (aTHX)
82     #define CORO_READY(coro) GCoroAPI->ready (aTHX_ coro)
83 root 1.11 #define CORO_IS_READY(coro) GCoroAPI->is_ready (coro)
84 root 1.26 #define CORO_NREADY (GCoroAPI->nready)
85     #define CORO_THROW (GCoroAPI->except)
86 root 1.22 #define CORO_CURRENT SvRV (GCoroAPI->current)
87 root 1.26 #define CORO_READYHOOK (GCoroAPI->readyhook)
88 root 1.21
89 root 1.17 #define I_CORO_API(YourName) \
90     STMT_START { \
91     SV *sv = perl_get_sv ("Coro::API", 0); \
92     if (!sv) croak ("Coro::API not found"); \
93     GCoroAPI = (struct CoroAPI*) SvIV (sv); \
94     if (GCoroAPI->ver != CORO_API_VERSION \
95     || GCoroAPI->rev < CORO_API_REVISION) \
96 root 1.16 croak ("Coro::API version mismatch (%d.%d vs. %d.%d) -- please recompile %s", \
97     GCoroAPI->ver, GCoroAPI->rev, CORO_API_VERSION, CORO_API_REVISION, YourName); \
98 root 1.1 } STMT_END
99    
100     #endif
101