ViewVC Help
View File | Revision Log | Show Annotations | Download File
/cvs/Coro/Coro/CoroAPI.h
Revision: 1.23
Committed: Sat Nov 15 18:40:55 2008 UTC (15 years, 6 months ago) by root
Content type: text/plain
Branch: MAIN
Changes since 1.22: +5 -5 lines
Log Message:
i hate windows process emulation

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     typedef void (*coro_slf_cb) (pTHX_ struct CoroSLF *frame, SV **arg, int items);
36    
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     void (*readyhook) (void);
49    
50     void (*schedule) (pTHX);
51 root 1.19 int (*cede) (pTHX);
52     int (*cede_notself) (pTHX);
53     int (*ready) (pTHX_ SV *coro_sv);
54     int (*is_ready) (pTHX_ SV *coro_sv);
55 root 1.18
56 root 1.20 /* Coro::State */
57     void (*transfer) (pTHX_ SV *prev_sv, SV *next_sv); /* Coro::State */
58 root 1.22
59     /* SLF */
60 root 1.21 struct coro *(*sv_state) (pTHX_ SV *coro);
61 root 1.22 void (*execute_slf) (pTHX_ CV *cv, coro_slf_cb init_cb, SV **arg, int nitems);
62     /* for use as CoroSLF.prepare */
63 root 1.23 void (*prepare_nop) (pTHX_ struct coro_transfer_args *ta);
64     void (*prepare_schedule) (pTHX_ struct coro_transfer_args *ta);
65     void (*prepare_cede) (pTHX_ struct coro_transfer_args *ta);
66     void (*prepare_cede_notself) (pTHX_ struct coro_transfer_args *ta);
67 root 1.1 };
68    
69     static struct CoroAPI *GCoroAPI;
70    
71 root 1.11 /* public API macros */
72     #define CORO_TRANSFER(prev,next) GCoroAPI->transfer (aTHX_ (prev), (next))
73 root 1.22
74     #define CORO_SV_STATE(coro) GCoroAPI->sv_state (aTHX_ (coro))
75     #define CORO_EXECUTE_SLF(cv,init,arg,items) GCoroAPI->execute_slf (aTHX_ (cv), (init), (arg), (items))
76     #define CORO_EXECUTE_SLF_XS(init) CORO_EXECUTE_SLF (cv, (init), &ST (0), items)
77    
78 root 1.19 #define CORO_SCHEDULE GCoroAPI->schedule (aTHX)
79     #define CORO_CEDE GCoroAPI->cede (aTHX)
80     #define CORO_CEDE_NOTSELF GCoroAPI->cede_notself (aTHX)
81     #define CORO_READY(coro) GCoroAPI->ready (aTHX_ coro)
82 root 1.11 #define CORO_IS_READY(coro) GCoroAPI->is_ready (coro)
83 root 1.22 #define CORO_NREADY GCoroAPI->nready
84     #define CORO_CURRENT SvRV (GCoroAPI->current)
85     #define CORO_READYHOOK GCoroAPI->readyhook
86 root 1.21
87 root 1.17 #define I_CORO_API(YourName) \
88     STMT_START { \
89     SV *sv = perl_get_sv ("Coro::API", 0); \
90     if (!sv) croak ("Coro::API not found"); \
91     GCoroAPI = (struct CoroAPI*) SvIV (sv); \
92     if (GCoroAPI->ver != CORO_API_VERSION \
93     || GCoroAPI->rev < CORO_API_REVISION) \
94 root 1.16 croak ("Coro::API version mismatch (%d.%d vs. %d.%d) -- please recompile %s", \
95     GCoroAPI->ver, GCoroAPI->rev, CORO_API_VERSION, CORO_API_REVISION, YourName); \
96 root 1.1 } STMT_END
97    
98     #endif
99