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