… | |
… | |
7 | #include <signal.h> |
7 | #include <signal.h> |
8 | |
8 | |
9 | #ifdef HAVE_MMAP |
9 | #ifdef HAVE_MMAP |
10 | # include <unistd.h> |
10 | # include <unistd.h> |
11 | # include <sys/mman.h> |
11 | # include <sys/mman.h> |
12 | # ifndef MAP_ANON |
|
|
13 | # ifdef MAP_ANONYMOUS |
12 | # ifndef MAP_ANONYMOUS |
14 | # define MAP_ANON MAP_ANONYMOUS |
13 | # ifdef MAP_ANON |
|
|
14 | # define MAP_ANONYMOUS MAP_ANON |
15 | # else |
15 | # else |
16 | # undef HAVE_MMAP |
16 | # undef HAVE_MMAP |
17 | # endif |
17 | # endif |
18 | # endif |
18 | # endif |
19 | #endif |
19 | #endif |
… | |
… | |
25 | |
25 | |
26 | /* The next macro should declare a variable stacklevel that contains and approximation |
26 | /* The next macro should declare a variable stacklevel that contains and approximation |
27 | * to the current C stack pointer. Its property is that it changes with each call |
27 | * to the current C stack pointer. Its property is that it changes with each call |
28 | * and should be unique. */ |
28 | * and should be unique. */ |
29 | #define dSTACKLEVEL void *stacklevel = &stacklevel |
29 | #define dSTACKLEVEL void *stacklevel = &stacklevel |
|
|
30 | |
|
|
31 | #define IN_DESTRUCT (PL_main_cv == Nullcv) |
30 | |
32 | |
31 | #define labs(l) ((l) >= 0 ? (l) : -(l)) |
33 | #define labs(l) ((l) >= 0 ? (l) : -(l)) |
32 | |
34 | |
33 | #include "CoroAPI.h" |
35 | #include "CoroAPI.h" |
34 | |
36 | |
… | |
… | |
487 | * still there is a memleak of 128 bytes... |
489 | * still there is a memleak of 128 bytes... |
488 | */ |
490 | */ |
489 | STATIC void |
491 | STATIC void |
490 | destroy_stacks(pTHX) |
492 | destroy_stacks(pTHX) |
491 | { |
493 | { |
492 | int destruct = PL_main_cv != Nullcv; |
494 | if (!IN_DESTRUCT) |
493 | |
|
|
494 | if (destruct) |
|
|
495 | { |
495 | { |
496 | /* is this ugly, I ask? */ |
496 | /* is this ugly, I ask? */ |
497 | while (PL_scopestack_ix) |
497 | while (PL_scopestack_ix) |
498 | LEAVE; |
498 | LEAVE; |
499 | |
499 | |
… | |
… | |
513 | dSP; |
513 | dSP; |
514 | SWITCHSTACK (PL_curstack, PL_curstackinfo->si_stack); |
514 | SWITCHSTACK (PL_curstack, PL_curstackinfo->si_stack); |
515 | PUTBACK; /* possibly superfluous */ |
515 | PUTBACK; /* possibly superfluous */ |
516 | } |
516 | } |
517 | |
517 | |
518 | if (destruct) |
518 | if (!IN_DESTRUCT) |
519 | { |
519 | { |
520 | dounwind(-1); |
520 | dounwind(-1); |
521 | SvREFCNT_dec(PL_curstackinfo->si_stack); |
521 | SvREFCNT_dec(PL_curstackinfo->si_stack); |
522 | } |
522 | } |
523 | |
523 | |
… | |
… | |
545 | stack->gencnt = ctx->gencnt = 0; |
545 | stack->gencnt = ctx->gencnt = 0; |
546 | if (alloc) |
546 | if (alloc) |
547 | { |
547 | { |
548 | #ifdef HAVE_MMAP |
548 | #ifdef HAVE_MMAP |
549 | stack->ssize = 128 * 1024 * sizeof (long); /* mmap should do allocate-on-write for us */ |
549 | stack->ssize = 128 * 1024 * sizeof (long); /* mmap should do allocate-on-write for us */ |
550 | stack->sptr = mmap (0, stack->ssize, PROT_EXEC|PROT_READ|PROT_WRITE, MAP_PRIVATE|MAP_ANON, 0, 0); |
550 | stack->sptr = mmap (0, stack->ssize, PROT_EXEC|PROT_READ|PROT_WRITE, MAP_PRIVATE|MAP_ANONYMOUS, 0, 0); |
551 | if (stack->sptr == (void *)-1) |
551 | if (stack->sptr == (void *)-1) |
552 | #endif |
552 | #endif |
553 | { |
553 | { |
554 | /*FIXME*//*D*//* reasonable stack size! */ |
554 | /*FIXME*//*D*//* reasonable stack size! */ |
555 | stack->ssize = -4096 * sizeof (long); |
555 | stack->ssize = -4096 * sizeof (long); |
… | |
… | |
744 | } |
744 | } |
745 | } |
745 | } |
746 | else |
746 | else |
747 | setup_coro (next); |
747 | setup_coro (next); |
748 | } |
748 | } |
749 | } |
|
|
750 | |
749 | |
751 | /* |
750 | /* |
752 | * xnext is now either prev or next, depending on wether |
751 | * xnext is now either prev or next, depending on wether |
753 | * we switched the c stack or not. that's why i use a global |
752 | * we switched the c stack or not. that's why i use a global |
754 | * variable, that should become thread-specific at one point. |
753 | * variable, that should become thread-specific at one point. |
755 | */ |
754 | */ |
756 | xnext->cursp = stacklevel; |
755 | xnext->cursp = stacklevel; |
|
|
756 | } |
757 | } |
757 | } |
758 | |
758 | |
759 | static struct coro * |
759 | static struct coro * |
760 | sv_to_coro (SV *arg, const char *funcname, const char *varname) |
760 | sv_to_coro (SV *arg, const char *funcname, const char *varname) |
761 | { |
761 | { |
… | |
… | |
1043 | } |
1043 | } |
1044 | |
1044 | |
1045 | void |
1045 | void |
1046 | ready(self) |
1046 | ready(self) |
1047 | SV * self |
1047 | SV * self |
|
|
1048 | PROTOTYPE: $ |
1048 | CODE: |
1049 | CODE: |
1049 | api_ready (self); |
1050 | api_ready (self); |
1050 | |
1051 | |
1051 | int |
1052 | int |
1052 | nready(...) |
1053 | nready(...) |