ViewVC Help
View File | Revision Log | Show Annotations | Download File
/cvs/Coro/Coro/CoroAPI.h
Revision: 1.5
Committed: Wed Nov 5 20:02:46 2003 UTC (21 years ago) by pcg
Content type: text/plain
Branch: MAIN
CVS Tags: rel-1_1, rel-1_0
Changes since 1.4: +7 -0 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 TRANSFER_SAVE_DEFAV 0x00000001 /* @_ */
17 #define TRANSFER_SAVE_DEFSV 0x00000002 /* $_ */
18 #define TRANSFER_SAVE_ERRSV 0x00000004 /* $@ */
19 /* c-related */
20 #define TRANSFER_SAVE_CCTXT 0x00000100
21 #ifdef CORO_LAZY_STACK
22 # define TRANSFER_LAZY_STACK 0x00000200
23 #else
24 # define TRANSFER_LAZY_STACK 0x00000000
25 #endif
26
27 #define TRANSFER_SAVE_ALL (TRANSFER_SAVE_DEFAV|TRANSFER_SAVE_DEFSV \
28 |TRANSFER_SAVE_ERRSV|TRANSFER_SAVE_CCTXT)
29
30 struct coro; /* opaque */
31
32 struct CoroAPI {
33 I32 ver;
34 #define CORO_API_VERSION 1
35
36 /* internal */
37 /*struct coro *(*sv_to_coro)(SV *arg, const char *funcname, const char *varname);*/
38
39 /* public, state */
40 void (*transfer)(pTHX_ SV *prev, SV *next, int flags);
41
42 /* public, coro */
43 void (*schedule)(void);
44 void (*cede)(void);
45 void (*ready)(SV *sv);
46 int *nready;
47 GV *current;
48 };
49
50 static struct CoroAPI *GCoroAPI;
51
52 #define CORO_TRANSFER(prev,next) GCoroAPI->transfer(aTHX_ (prev),(next))
53 #define CORO_SCHEDULE GCoroAPI->schedule()
54 #define CORO_CEDE GCoroAPI->cede()
55 #define CORO_READY(coro) GCoroAPI->ready(coro)
56 #define CORO_NREADY (*GCoroAPI->nready)
57 #define CORO_CURRENT SvRV(GvSV(GCoroAPI->current))
58
59 #define I_CORO_API(YourName) \
60 STMT_START { \
61 SV *sv = perl_get_sv("Coro::API",0); \
62 if (!sv) croak("Coro::API not found"); \
63 GCoroAPI = (struct CoroAPI*) SvIV(sv); \
64 if (GCoroAPI->ver != CORO_API_VERSION) { \
65 croak("Coro::API version mismatch (%d != %d) -- please recompile %s", \
66 GCoroAPI->ver, CORO_API_VERSION, YourName); \
67 } \
68 } STMT_END
69
70 #endif
71