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.9 |
/*struct coro;*/ /* opaque */ |
16 |
root |
1.1 |
|
17 |
root |
1.19 |
enum { |
18 |
|
|
CORO_SLF_SCHEDULE = 3, |
19 |
|
|
CORO_SLF_CEDE = 4, |
20 |
|
|
CORO_SLF_CEDE_NOTSELF = 5 |
21 |
|
|
}; |
22 |
|
|
|
23 |
|
|
struct CoroSLF |
24 |
|
|
{ |
25 |
|
|
int (*prepare) (pTHX_ SV **arg, int items); /* returns CORO_SLF_* */ |
26 |
|
|
int (*check) (pTHX); /* returns repeat-flag */ |
27 |
|
|
}; |
28 |
|
|
|
29 |
root |
1.10 |
/* private structure, always use the provided macros below */ |
30 |
root |
1.19 |
struct CoroAPI |
31 |
|
|
{ |
32 |
root |
1.1 |
I32 ver; |
33 |
root |
1.15 |
I32 rev; |
34 |
root |
1.19 |
#define CORO_API_VERSION 7 |
35 |
|
|
#define CORO_API_REVISION 0 |
36 |
|
|
|
37 |
root |
1.20 |
/* Coro */ |
38 |
|
|
int nready; |
39 |
|
|
SV *current; |
40 |
|
|
void (*readyhook) (void); |
41 |
|
|
|
42 |
|
|
void (*schedule) (pTHX); |
43 |
root |
1.19 |
int (*cede) (pTHX); |
44 |
|
|
int (*cede_notself) (pTHX); |
45 |
|
|
int (*ready) (pTHX_ SV *coro_sv); |
46 |
|
|
int (*is_ready) (pTHX_ SV *coro_sv); |
47 |
root |
1.18 |
|
48 |
root |
1.20 |
/* Coro::State */ |
49 |
|
|
void (*transfer) (pTHX_ SV *prev_sv, SV *next_sv); /* Coro::State */ |
50 |
|
|
void (*execute_slf) (pTHX_ CV *cv, const struct CoroSLF *slf, SV **arg, int nitems); |
51 |
|
|
|
52 |
root |
1.1 |
}; |
53 |
|
|
|
54 |
|
|
static struct CoroAPI *GCoroAPI; |
55 |
|
|
|
56 |
root |
1.11 |
/* public API macros */ |
57 |
|
|
#define CORO_TRANSFER(prev,next) GCoroAPI->transfer (aTHX_ (prev), (next)) |
58 |
root |
1.19 |
#define CORO_SCHEDULE GCoroAPI->schedule (aTHX) |
59 |
|
|
#define CORO_CEDE GCoroAPI->cede (aTHX) |
60 |
|
|
#define CORO_CEDE_NOTSELF GCoroAPI->cede_notself (aTHX) |
61 |
|
|
#define CORO_READY(coro) GCoroAPI->ready (aTHX_ coro) |
62 |
root |
1.11 |
#define CORO_IS_READY(coro) GCoroAPI->is_ready (coro) |
63 |
root |
1.19 |
#define CORO_NREADY GCoroAPI->nready |
64 |
root |
1.11 |
#define CORO_CURRENT SvRV (GCoroAPI->current) |
65 |
root |
1.19 |
#define CORO_READYHOOK GCoroAPI->readyhook |
66 |
root |
1.20 |
|
67 |
|
|
#define CORO_EXECUTE_SLF(cv,slf,arg,nitems) GCoroAPI->execute_slf (aTHX_ (cv), &(slf), (arg), (nitems)) |
68 |
|
|
#define CORO_EXECUTE_SLF_XS(slf) CORO_EXECUTE_SLF (cv, (slf), &ST (0), nitems) |
69 |
root |
1.1 |
|
70 |
root |
1.17 |
#define I_CORO_API(YourName) \ |
71 |
|
|
STMT_START { \ |
72 |
|
|
SV *sv = perl_get_sv ("Coro::API", 0); \ |
73 |
|
|
if (!sv) croak ("Coro::API not found"); \ |
74 |
|
|
GCoroAPI = (struct CoroAPI*) SvIV (sv); \ |
75 |
|
|
if (GCoroAPI->ver != CORO_API_VERSION \ |
76 |
|
|
|| GCoroAPI->rev < CORO_API_REVISION) \ |
77 |
root |
1.16 |
croak ("Coro::API version mismatch (%d.%d vs. %d.%d) -- please recompile %s", \ |
78 |
|
|
GCoroAPI->ver, GCoroAPI->rev, CORO_API_VERSION, CORO_API_REVISION, YourName); \ |
79 |
root |
1.1 |
} STMT_END |
80 |
|
|
|
81 |
|
|
#endif |
82 |
|
|
|