ViewVC Help
View File | Revision Log | Show Annotations | Download File
/cvs/Coro/Coro/CoroAPI.h
Revision: 1.11
Committed: Mon Dec 4 13:47:56 2006 UTC (17 years, 6 months ago) by root
Content type: text/plain
Branch: MAIN
CVS Tags: rel-3_1, rel-3_2, rel-3_11
Changes since 1.10: +24 -18 lines
Log Message:
*** empty log message ***

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 /* perl-related */
16 #define CORO_SAVE_DEFAV 0x00000001 /* @_ */
17 #define CORO_SAVE_DEFSV 0x00000002 /* $_ */
18 #define CORO_SAVE_ERRSV 0x00000004 /* $@ */
19 #define CORO_SAVE_IRSSV 0x00000008 /* $/ */
20
21 #define CORO_SAVE_ALL ( CORO_SAVE_DEFAV \
22 | CORO_SAVE_DEFSV \
23 | CORO_SAVE_ERRSV \
24 | CORO_SAVE_IRSSV )
25
26 /*struct coro;*/ /* opaque */
27
28 /* private structure, always use the provided macros below */
29 struct CoroAPI {
30 I32 ver;
31 #define CORO_API_VERSION 3
32 #define CORO_API_REVISION 0
33
34 /* internal */
35 /*struct coro *(*sv_to_coro)(SV *arg, const char *funcname, const char *varname);*/
36
37 /* private API, Coro::State */
38 void (*transfer) (SV *prev_sv, SV *next_sv);
39 int (*save) (SV *coro_sv, int new_save);
40
41 /* private API, Coro */
42 void (*schedule) (void);
43 void (*cede) (void);
44 int (*ready) (SV *coro_sv);
45 int (*is_ready) (SV *coro_sv);
46 int *nready;
47 SV *current;
48 };
49
50 static struct CoroAPI *GCoroAPI;
51
52 /* public API macros */
53 #define CORO_TRANSFER(prev,next) GCoroAPI->transfer (aTHX_ (prev), (next))
54 #define CORO_SCHEDULE GCoroAPI->schedule ()
55 #define CORO_CEDE GCoroAPI->cede ()
56 #define CORO_READY(coro) GCoroAPI->ready (coro)
57 #define CORO_IS_READY(coro) GCoroAPI->is_ready (coro)
58 #define CORO_NREADY (*GCoroAPI->nready)
59 #define CORO_CURRENT SvRV (GCoroAPI->current)
60 #define CORO_GET_SAVE(coro) GCoroAPI->save ((coro), -1)
61 #define CORO_SET_SAVE(coro,save) GCoroAPI->save ((coro), (save))
62
63 #define I_CORO_API(YourName) \
64 STMT_START { \
65 SV *sv = perl_get_sv("Coro::API",0); \
66 if (!sv) croak("Coro::API not found"); \
67 GCoroAPI = (struct CoroAPI*) SvIV(sv); \
68 if (GCoroAPI->ver != CORO_API_VERSION) { \
69 croak("Coro::API version mismatch (%d != %d) -- please recompile %s", \
70 GCoroAPI->ver, CORO_API_VERSION, YourName); \
71 } \
72 } STMT_END
73
74 #endif
75