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 |
void (*transfer) (SV *prev_sv, SV *next_sv); /* Coro::State */ |
24 |
|
25 |
void (*schedule) (void); /* Coro */ |
26 |
int (*cede) (void); |
27 |
int (*cede_notself) (void); |
28 |
int (*ready) (SV *coro_sv); |
29 |
int (*is_ready) (SV *coro_sv); |
30 |
int *nready; |
31 |
SV *current; |
32 |
|
33 |
SV *(*coro_event_next)(SV *watcher, int cancel, int wantev); /* Coro::Event::next */ |
34 |
}; |
35 |
|
36 |
static struct CoroAPI *GCoroAPI; |
37 |
|
38 |
/* public API macros */ |
39 |
#define CORO_TRANSFER(prev,next) GCoroAPI->transfer (aTHX_ (prev), (next)) |
40 |
#define CORO_SCHEDULE GCoroAPI->schedule () |
41 |
#define CORO_CEDE GCoroAPI->cede () |
42 |
#define CORO_CEDE_NOTSELF GCoroAPI->cede_notself () |
43 |
#define CORO_READY(coro) GCoroAPI->ready (coro) |
44 |
#define CORO_IS_READY(coro) GCoroAPI->is_ready (coro) |
45 |
#define CORO_NREADY (*GCoroAPI->nready) |
46 |
#define CORO_CURRENT SvRV (GCoroAPI->current) |
47 |
|
48 |
#define I_CORO_API(YourName) \ |
49 |
STMT_START { \ |
50 |
SV *sv = perl_get_sv ("Coro::API", 0); \ |
51 |
if (!sv) croak ("Coro::API not found"); \ |
52 |
GCoroAPI = (struct CoroAPI*) SvIV (sv); \ |
53 |
if (GCoroAPI->ver != CORO_API_VERSION \ |
54 |
|| GCoroAPI->rev < CORO_API_REVISION) \ |
55 |
croak ("Coro::API version mismatch (%d.%d vs. %d.%d) -- please recompile %s", \ |
56 |
GCoroAPI->ver, GCoroAPI->rev, CORO_API_VERSION, CORO_API_REVISION, YourName); \ |
57 |
} STMT_END |
58 |
|
59 |
#endif |
60 |
|