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 |
|
|
/* perl-related */ |
9 |
root |
1.3 |
#define TRANSFER_SAVE_DEFAV 0x00000001 /* @_ */ |
10 |
|
|
#define TRANSFER_SAVE_DEFSV 0x00000002 /* $_ */ |
11 |
|
|
#define TRANSFER_SAVE_ERRSV 0x00000004 /* $@ */ |
12 |
|
|
#define TRANSFER_SAVE_CURPM 0x00000008 /* regex results */ |
13 |
root |
1.1 |
/* c-related */ |
14 |
root |
1.3 |
#define TRANSFER_SAVE_CCTXT 0x00000100 |
15 |
root |
1.1 |
#ifdef CORO_LAZY_STACK |
16 |
root |
1.3 |
# define TRANSFER_LAZY_STACK 0x00000200 |
17 |
root |
1.1 |
#else |
18 |
|
|
# define TRANSFER_LAZY_STACK 0x00000000 |
19 |
|
|
#endif |
20 |
|
|
|
21 |
|
|
#define TRANSFER_SAVE_ALL (TRANSFER_SAVE_DEFAV|TRANSFER_SAVE_DEFSV \ |
22 |
root |
1.3 |
|TRANSFER_SAVE_ERRSV|TRANSFER_SAVE_CURPM \ |
23 |
|
|
|TRANSFER_SAVE_CCTXT) |
24 |
root |
1.1 |
|
25 |
|
|
struct coro; /* opaque */ |
26 |
|
|
|
27 |
|
|
struct CoroAPI { |
28 |
|
|
I32 ver; |
29 |
|
|
#define CORO_API_VERSION 1 |
30 |
|
|
|
31 |
|
|
/* internal */ |
32 |
|
|
/*struct coro *(*sv_to_coro)(SV *arg, const char *funcname, const char *varname);*/ |
33 |
|
|
|
34 |
|
|
/* public, state */ |
35 |
|
|
void (*transfer)(pTHX_ SV *prev, SV *next, int flags); |
36 |
|
|
|
37 |
|
|
/* public, coro */ |
38 |
root |
1.2 |
void (*schedule)(void); |
39 |
|
|
void (*cede)(void); |
40 |
root |
1.1 |
void (*ready)(SV *sv); |
41 |
|
|
int *nready; |
42 |
|
|
GV *current; |
43 |
|
|
}; |
44 |
|
|
|
45 |
|
|
static struct CoroAPI *GCoroAPI; |
46 |
|
|
|
47 |
|
|
#define CORO_TRANSFER(prev,next) GCoroAPI->transfer(aTHX_ (prev),(next)) |
48 |
root |
1.2 |
#define CORO_SCHEDULE GCoroAPI->schedule() |
49 |
|
|
#define CORO_CEDE GCoroAPI->cede() |
50 |
root |
1.1 |
#define CORO_READY(coro) GCoroAPI->ready(coro) |
51 |
|
|
#define CORO_NREADY (*GCoroAPI->nready) |
52 |
root |
1.2 |
#define CORO_CURRENT SvRV(GvSV(GCoroAPI->current)) |
53 |
root |
1.1 |
|
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 |
|
|
} \ |
63 |
|
|
} STMT_END |
64 |
|
|
|
65 |
|
|
#endif |
66 |
|
|
|