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 |
root |
1.9 |
/*struct coro;*/ /* opaque */ |
25 |
root |
1.1 |
|
26 |
root |
1.10 |
/* private structure, always use the provided macros below */ |
27 |
root |
1.1 |
struct CoroAPI { |
28 |
|
|
I32 ver; |
29 |
root |
1.9 |
#define CORO_API_VERSION 2 |
30 |
|
|
#define CORO_API_REVISION 0 |
31 |
root |
1.1 |
|
32 |
|
|
/* internal */ |
33 |
|
|
/*struct coro *(*sv_to_coro)(SV *arg, const char *funcname, const char *varname);*/ |
34 |
|
|
|
35 |
root |
1.10 |
/* public API, Coro::State */ |
36 |
root |
1.9 |
void (*transfer) (SV *prev, SV *next, int flags); |
37 |
root |
1.1 |
|
38 |
root |
1.10 |
/* public API, Coro */ |
39 |
root |
1.9 |
void (*schedule) (void); |
40 |
|
|
void (*cede) (void); |
41 |
|
|
int (*ready) (SV *coro_sv); |
42 |
|
|
int (*is_ready) (SV *coro_sv); |
43 |
root |
1.1 |
int *nready; |
44 |
root |
1.10 |
SV *current; |
45 |
root |
1.1 |
}; |
46 |
|
|
|
47 |
|
|
static struct CoroAPI *GCoroAPI; |
48 |
|
|
|
49 |
root |
1.9 |
#define CORO_TRANSFER(prev,next,flags) GCoroAPI->transfer (aTHX_ (prev), (next), (flags)) |
50 |
|
|
#define CORO_SCHEDULE GCoroAPI->schedule () |
51 |
|
|
#define CORO_CEDE GCoroAPI->cede () |
52 |
|
|
#define CORO_READY(coro) GCoroAPI->ready (coro) |
53 |
|
|
#define CORO_IS_READY(coro) GCoroAPI->is_ready (coro) |
54 |
|
|
#define CORO_NREADY (*GCoroAPI->nready) |
55 |
root |
1.10 |
#define CORO_CURRENT SvRV (GCoroAPI->current) |
56 |
root |
1.1 |
|
57 |
|
|
#define I_CORO_API(YourName) \ |
58 |
|
|
STMT_START { \ |
59 |
|
|
SV *sv = perl_get_sv("Coro::API",0); \ |
60 |
|
|
if (!sv) croak("Coro::API not found"); \ |
61 |
|
|
GCoroAPI = (struct CoroAPI*) SvIV(sv); \ |
62 |
|
|
if (GCoroAPI->ver != CORO_API_VERSION) { \ |
63 |
|
|
croak("Coro::API version mismatch (%d != %d) -- please recompile %s", \ |
64 |
|
|
GCoroAPI->ver, CORO_API_VERSION, YourName); \ |
65 |
|
|
} \ |
66 |
|
|
} STMT_END |
67 |
|
|
|
68 |
|
|
#endif |
69 |
|
|
|