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.416 by root, Mon Dec 12 15:19:56 2011 UTC vs.
Revision 1.419 by root, Mon Feb 20 08:13:25 2012 UTC

101# if CORO_PTHREAD 101# if CORO_PTHREAD
102static void *coro_thx; 102static void *coro_thx;
103# endif 103# endif
104#endif 104#endif
105 105
106/* used in state.h */
107#define VAR(name,type) VARx(name, PL_ ## name, type)
108
109#ifdef __linux 106#ifdef __linux
110# include <time.h> /* for timespec */ 107# include <time.h> /* for timespec */
111# include <syscall.h> /* for SYS_* */ 108# include <syscall.h> /* for SYS_* */
112# ifdef SYS_clock_gettime 109# ifdef SYS_clock_gettime
113# define coro_clock_gettime(id, ts) syscall (SYS_clock_gettime, (id), (ts)) 110# define coro_clock_gettime(id, ts) syscall (SYS_clock_gettime, (id), (ts))
213}; 210};
214 211
215/* the structure where most of the perl state is stored, overlaid on the cxstack */ 212/* the structure where most of the perl state is stored, overlaid on the cxstack */
216typedef struct 213typedef struct
217{ 214{
218#define VARx(name,expr,type) type name; 215 #define VARx(name,expr,type) type name;
219# include "state.h" 216 #include "state.h"
220#undef VARx
221} perl_slots; 217} perl_slots;
222 218
223/* how many context stack entries do we need for perl_slots */ 219/* how many context stack entries do we need for perl_slots */
224#define SLOT_COUNT ((sizeof (perl_slots) + sizeof (PERL_CONTEXT) - 1) / sizeof (PERL_CONTEXT)) 220#define SLOT_COUNT ((sizeof (perl_slots) + sizeof (PERL_CONTEXT) - 1) / sizeof (PERL_CONTEXT))
225 221
710 706
711#if CORO_JIT 707#if CORO_JIT
712 load_perl_slots (slot); 708 load_perl_slots (slot);
713#else 709#else
714 #define VARx(name,expr,type) expr = slot->name; 710 #define VARx(name,expr,type) expr = slot->name;
715 # include "state.h" 711 #include "state.h"
716 #undef VARx
717#endif 712#endif
718 713
719 { 714 {
720 dSP; 715 dSP;
721 716
843 838
844#if CORO_JIT 839#if CORO_JIT
845 save_perl_slots (slot); 840 save_perl_slots (slot);
846#else 841#else
847 #define VARx(name,expr,type) slot->name = expr; 842 #define VARx(name,expr,type) slot->name = expr;
848 # include "state.h" 843 #include "state.h"
849 #undef VARx
850#endif 844#endif
851 } 845 }
852} 846}
853 847
854/* 848/*
1417transfer_tail (pTHX) 1411transfer_tail (pTHX)
1418{ 1412{
1419 free_coro_mortal (aTHX); 1413 free_coro_mortal (aTHX);
1420} 1414}
1421 1415
1416/* try to exit the same way perl's main function would do */
1417/* we do not bother resetting the environment or other things *7
1418/* that are not, uhm, essential */
1419/* this obviously also doesn't work when perl is embedded */
1420static void ecb_noinline ecb_cold
1421perlish_exit (void)
1422{
1423 int exitstatus = perl_destruct (PL_curinterp);
1424 perl_free (PL_curinterp);
1425 exit (exitstatus);
1426}
1427
1422/* 1428/*
1423 * this is a _very_ stripped down perl interpreter ;) 1429 * this is a _very_ stripped down perl interpreter ;)
1424 */ 1430 */
1425static void 1431static void
1426cctx_run (void *arg) 1432cctx_run (void *arg)
1453 */ 1459 */
1454 1460
1455 /* 1461 /*
1456 * If perl-run returns we assume exit() was being called or the coro 1462 * If perl-run returns we assume exit() was being called or the coro
1457 * fell off the end, which seems to be the only valid (non-bug) 1463 * fell off the end, which seems to be the only valid (non-bug)
1458 * reason for perl_run to return. We try to exit by jumping to the 1464 * reason for perl_run to return. We try to mimic whatever perl is normally
1459 * bootstrap-time "top" top_env, as we cannot restore the "main" 1465 * doing in that case. YMMV.
1460 * coroutine as Coro has no such concept.
1461 * This actually isn't valid with the pthread backend, but OSes requiring
1462 * that backend are too broken to do it in a standards-compliant way.
1463 */ 1466 */
1464 PL_top_env = main_top_env; 1467 perlish_exit ();
1465 JMPENV_JUMP (2); /* I do not feel well about the hardcoded 2 at all */
1466 } 1468 }
1467} 1469}
1468 1470
1469static coro_cctx * 1471static coro_cctx *
1470cctx_new (void) 1472cctx_new (void)
3393 int count; 3395 int count;
3394 3396
3395 eval_pv ("require 'Coro/jit-" CORO_JIT_TYPE ".pl'", 1); 3397 eval_pv ("require 'Coro/jit-" CORO_JIT_TYPE ".pl'", 1);
3396 3398
3397 PUSHMARK (SP); 3399 PUSHMARK (SP);
3398#define VARx(name,expr,type) pushav_4uv (aTHX_ (UV)&(expr), sizeof (expr), offsetof (perl_slots, name), sizeof (type)); 3400 #define VARx(name,expr,type) pushav_4uv (aTHX_ (UV)&(expr), sizeof (expr), offsetof (perl_slots, name), sizeof (type));
3399# include "state.h" 3401 #include "state.h"
3400#undef VARx
3401 count = call_pv ("Coro::State::_jit", G_ARRAY); 3402 count = call_pv ("Coro::State::_jit", G_ARRAY);
3402 SPAGAIN; 3403 SPAGAIN;
3403 3404
3404 save = POPs; save_ptr = SvPVbyte (save, save_len); 3405 save = POPs; save_ptr = SvPVbyte (save, save_len);
3405 load = POPs; load_ptr = SvPVbyte (load, load_len); 3406 load = POPs; load_ptr = SvPVbyte (load, load_len);

Diff Legend

Removed lines
+ Added lines
< Changed lines
> Changed lines