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