ViewVC Help
View File | Revision Log | Show Annotations | Download File
/cvs/Coro/Coro/State.xs
(Generate patch)

Comparing Coro/Coro/State.xs (file contents):
Revision 1.426 by root, Wed Dec 5 00:19:57 2012 UTC vs.
Revision 1.427 by root, Wed Dec 5 14:35:34 2012 UTC

1533{ 1533{
1534 coro_cctx *cctx = cctx_new (); 1534 coro_cctx *cctx = cctx_new ();
1535 void *stack_start; 1535 void *stack_start;
1536 size_t stack_size; 1536 size_t stack_size;
1537 1537
1538#if CORO_FIBER
1539
1540 cctx->ssize = cctx_stacksize * sizeof (long);
1541 cctx->sptr = 0;
1542
1543#else
1544
1538#if HAVE_MMAP 1545 #if HAVE_MMAP
1539 cctx->ssize = ((cctx_stacksize * sizeof (long) + PAGESIZE - 1) / PAGESIZE + CORO_STACKGUARD) * PAGESIZE; 1546 cctx->ssize = ((cctx_stacksize * sizeof (long) + PAGESIZE - 1) / PAGESIZE + CORO_STACKGUARD) * PAGESIZE;
1540 /* mmap supposedly does allocate-on-write for us */ 1547 /* mmap supposedly does allocate-on-write for us */
1541 cctx->sptr = mmap (0, cctx->ssize, PROT_READ | PROT_WRITE | PROT_EXEC, MAP_ANONYMOUS, -1, 0); 1548 cctx->sptr = mmap (0, cctx->ssize, PROT_READ | PROT_WRITE | PROT_EXEC, MAP_ANONYMOUS, -1, 0);
1542 1549
1543 if (cctx->sptr != (void *)-1) 1550 if (cctx->sptr != (void *)-1)
1544 { 1551 {
1545 #if CORO_STACKGUARD 1552 #if CORO_STACKGUARD
1546 mprotect (cctx->sptr, CORO_STACKGUARD * PAGESIZE, PROT_NONE); 1553 mprotect (cctx->sptr, CORO_STACKGUARD * PAGESIZE, PROT_NONE);
1547 #endif 1554 #endif
1548 stack_start = (char *)cctx->sptr + CORO_STACKGUARD * PAGESIZE; 1555 stack_start = (char *)cctx->sptr + CORO_STACKGUARD * PAGESIZE;
1549 stack_size = cctx->ssize - CORO_STACKGUARD * PAGESIZE; 1556 stack_size = cctx->ssize - CORO_STACKGUARD * PAGESIZE;
1550 cctx->flags |= CC_MAPPED; 1557 cctx->flags |= CC_MAPPED;
1551 } 1558 }
1552 else 1559 else
1553#endif 1560 #endif
1554 { 1561 {
1555 cctx->ssize = cctx_stacksize * (long)sizeof (long); 1562 cctx->ssize = cctx_stacksize * (long)sizeof (long);
1556 New (0, cctx->sptr, cctx_stacksize, long); 1563 New (0, cctx->sptr, cctx_stacksize, long);
1557 1564
1558 if (!cctx->sptr) 1565 if (!cctx->sptr)
1559 { 1566 {
1560 perror ("FATAL: unable to allocate stack for coroutine, exiting."); 1567 perror ("FATAL: unable to allocate stack for coroutine, exiting.");
1561 _exit (EXIT_FAILURE); 1568 _exit (EXIT_FAILURE);
1562 } 1569 }
1563 1570
1564 stack_start = cctx->sptr; 1571 stack_start = cctx->sptr;
1565 stack_size = cctx->ssize; 1572 stack_size = cctx->ssize;
1566 } 1573 }
1574 #endif
1567 1575
1568 #if CORO_USE_VALGRIND 1576 #if CORO_USE_VALGRIND
1569 cctx->valgrind_id = VALGRIND_STACK_REGISTER ((char *)stack_start, (char *)stack_start + stack_size); 1577 cctx->valgrind_id = VALGRIND_STACK_REGISTER ((char *)stack_start, (char *)stack_start + stack_size);
1570 #endif 1578 #endif
1571 1579

Diff Legend

Removed lines
+ Added lines
< Changed lines
> Changed lines