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 |
/*struct coro;*/ /* opaque */ |
16 |
|
17 |
/* private structure, always use the provided macros below */ |
18 |
struct CoroAPI { |
19 |
I32 ver; |
20 |
I32 rev; |
21 |
#define CORO_API_VERSION 6 |
22 |
#define CORO_API_REVISION 0 |
23 |
|
24 |
/* internal */ |
25 |
/*struct coro *(*sv_to_coro)(SV *arg, const char *funcname, const char *varname);*/ |
26 |
|
27 |
/* private API, Coro::State */ |
28 |
void (*transfer) (SV *prev_sv, SV *next_sv); |
29 |
|
30 |
/* private API, Coro */ |
31 |
void (*schedule) (void); |
32 |
int (*cede) (void); |
33 |
int (*cede_notself) (void); |
34 |
int (*ready) (SV *coro_sv); |
35 |
int (*is_ready) (SV *coro_sv); |
36 |
int *nready; |
37 |
SV *current; |
38 |
|
39 |
SV *(*coro_event_next)(SV *watcher, int cancel, int wantev); |
40 |
}; |
41 |
|
42 |
static struct CoroAPI *GCoroAPI; |
43 |
|
44 |
/* public API macros */ |
45 |
#define CORO_TRANSFER(prev,next) GCoroAPI->transfer (aTHX_ (prev), (next)) |
46 |
#define CORO_SCHEDULE GCoroAPI->schedule () |
47 |
#define CORO_CEDE GCoroAPI->cede () |
48 |
#define CORO_CEDE_NOTSELF GCoroAPI->cede_notself () |
49 |
#define CORO_READY(coro) GCoroAPI->ready (coro) |
50 |
#define CORO_IS_READY(coro) GCoroAPI->is_ready (coro) |
51 |
#define CORO_NREADY (*GCoroAPI->nready) |
52 |
#define CORO_CURRENT SvRV (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 |
if (GCoroAPI->rev < CORO_API_REVISION) \ |
63 |
croak("Coro::API revision outdated (%d != %d) -- please recompile %s", \ |
64 |
GCoroAPI->rev, CORO_API_REVISION, YourName); \ |
65 |
} STMT_END |
66 |
|
67 |
#endif |
68 |
|