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.12 |
#define CORO_API_VERSION 4 |
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 |
root |
1.12 |
int (*cede) (void); |
44 |
|
|
int (*cede_notself) (void); |
45 |
root |
1.9 |
int (*ready) (SV *coro_sv); |
46 |
|
|
int (*is_ready) (SV *coro_sv); |
47 |
root |
1.1 |
int *nready; |
48 |
root |
1.10 |
SV *current; |
49 |
root |
1.1 |
}; |
50 |
|
|
|
51 |
|
|
static struct CoroAPI *GCoroAPI; |
52 |
|
|
|
53 |
root |
1.11 |
/* public API macros */ |
54 |
|
|
#define CORO_TRANSFER(prev,next) GCoroAPI->transfer (aTHX_ (prev), (next)) |
55 |
|
|
#define CORO_SCHEDULE GCoroAPI->schedule () |
56 |
|
|
#define CORO_CEDE GCoroAPI->cede () |
57 |
root |
1.12 |
#define CORO_CEDE_NOTSELF GCoroAPI->cede_notself () |
58 |
root |
1.11 |
#define CORO_READY(coro) GCoroAPI->ready (coro) |
59 |
|
|
#define CORO_IS_READY(coro) GCoroAPI->is_ready (coro) |
60 |
|
|
#define CORO_NREADY (*GCoroAPI->nready) |
61 |
|
|
#define CORO_CURRENT SvRV (GCoroAPI->current) |
62 |
|
|
#define CORO_GET_SAVE(coro) GCoroAPI->save ((coro), -1) |
63 |
|
|
#define CORO_SET_SAVE(coro,save) GCoroAPI->save ((coro), (save)) |
64 |
root |
1.1 |
|
65 |
|
|
#define I_CORO_API(YourName) \ |
66 |
|
|
STMT_START { \ |
67 |
|
|
SV *sv = perl_get_sv("Coro::API",0); \ |
68 |
|
|
if (!sv) croak("Coro::API not found"); \ |
69 |
|
|
GCoroAPI = (struct CoroAPI*) SvIV(sv); \ |
70 |
|
|
if (GCoroAPI->ver != CORO_API_VERSION) { \ |
71 |
|
|
croak("Coro::API version mismatch (%d != %d) -- please recompile %s", \ |
72 |
|
|
GCoroAPI->ver, CORO_API_VERSION, YourName); \ |
73 |
|
|
} \ |
74 |
|
|
} STMT_END |
75 |
|
|
|
76 |
|
|
#endif |
77 |
|
|
|