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.11 |
#define CORO_SAVE_DEFAV 0x00000001 /* @_ */ |
17 |
|
|
#define CORO_SAVE_DEFSV 0x00000002 /* $_ */ |
18 |
|
|
#define CORO_SAVE_ERRSV 0x00000004 /* $@ */ |
19 |
|
|
#define CORO_SAVE_IRSSV 0x00000008 /* $/ */ |
20 |
|
|
|
21 |
|
|
#define CORO_SAVE_ALL ( CORO_SAVE_DEFAV \ |
22 |
|
|
| CORO_SAVE_DEFSV \ |
23 |
|
|
| CORO_SAVE_ERRSV \ |
24 |
|
|
| CORO_SAVE_IRSSV ) |
25 |
root |
1.1 |
|
26 |
root |
1.9 |
/*struct coro;*/ /* opaque */ |
27 |
root |
1.1 |
|
28 |
root |
1.10 |
/* private structure, always use the provided macros below */ |
29 |
root |
1.1 |
struct CoroAPI { |
30 |
|
|
I32 ver; |
31 |
root |
1.11 |
#define CORO_API_VERSION 3 |
32 |
root |
1.9 |
#define CORO_API_REVISION 0 |
33 |
root |
1.1 |
|
34 |
|
|
/* internal */ |
35 |
|
|
/*struct coro *(*sv_to_coro)(SV *arg, const char *funcname, const char *varname);*/ |
36 |
|
|
|
37 |
root |
1.11 |
/* private API, Coro::State */ |
38 |
|
|
void (*transfer) (SV *prev_sv, SV *next_sv); |
39 |
|
|
int (*save) (SV *coro_sv, int new_save); |
40 |
root |
1.1 |
|
41 |
root |
1.11 |
/* private API, Coro */ |
42 |
root |
1.9 |
void (*schedule) (void); |
43 |
|
|
void (*cede) (void); |
44 |
|
|
int (*ready) (SV *coro_sv); |
45 |
|
|
int (*is_ready) (SV *coro_sv); |
46 |
root |
1.1 |
int *nready; |
47 |
root |
1.10 |
SV *current; |
48 |
root |
1.1 |
}; |
49 |
|
|
|
50 |
|
|
static struct CoroAPI *GCoroAPI; |
51 |
|
|
|
52 |
root |
1.11 |
/* public API macros */ |
53 |
|
|
#define CORO_TRANSFER(prev,next) GCoroAPI->transfer (aTHX_ (prev), (next)) |
54 |
|
|
#define CORO_SCHEDULE GCoroAPI->schedule () |
55 |
|
|
#define CORO_CEDE GCoroAPI->cede () |
56 |
|
|
#define CORO_READY(coro) GCoroAPI->ready (coro) |
57 |
|
|
#define CORO_IS_READY(coro) GCoroAPI->is_ready (coro) |
58 |
|
|
#define CORO_NREADY (*GCoroAPI->nready) |
59 |
|
|
#define CORO_CURRENT SvRV (GCoroAPI->current) |
60 |
|
|
#define CORO_GET_SAVE(coro) GCoroAPI->save ((coro), -1) |
61 |
|
|
#define CORO_SET_SAVE(coro,save) GCoroAPI->save ((coro), (save)) |
62 |
root |
1.1 |
|
63 |
|
|
#define I_CORO_API(YourName) \ |
64 |
|
|
STMT_START { \ |
65 |
|
|
SV *sv = perl_get_sv("Coro::API",0); \ |
66 |
|
|
if (!sv) croak("Coro::API not found"); \ |
67 |
|
|
GCoroAPI = (struct CoroAPI*) SvIV(sv); \ |
68 |
|
|
if (GCoroAPI->ver != CORO_API_VERSION) { \ |
69 |
|
|
croak("Coro::API version mismatch (%d != %d) -- please recompile %s", \ |
70 |
|
|
GCoroAPI->ver, CORO_API_VERSION, YourName); \ |
71 |
|
|
} \ |
72 |
|
|
} STMT_END |
73 |
|
|
|
74 |
|
|
#endif |
75 |
|
|
|