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.438 by root, Mon Nov 18 10:27:53 2013 UTC vs.
Revision 1.446 by root, Wed Sep 3 14:26:34 2014 UTC

14#include "perliol.h" 14#include "perliol.h"
15 15
16#include "schmorp.h" 16#include "schmorp.h"
17 17
18#define ECB_NO_THREADS 1 18#define ECB_NO_THREADS 1
19#define ECB_NO_LIBM 1
19#include "ecb.h" 20#include "ecb.h"
20 21
21#include <stddef.h> 22#include <stddef.h>
22#include <stdio.h> 23#include <stdio.h>
23#include <errno.h> 24#include <errno.h>
1137 1138
1138 GvSV (PL_defgv) = newSV (0); 1139 GvSV (PL_defgv) = newSV (0);
1139 GvAV (PL_defgv) = coro->args; coro->args = 0; 1140 GvAV (PL_defgv) = coro->args; coro->args = 0;
1140 GvSV (PL_errgv) = newSV (0); 1141 GvSV (PL_errgv) = newSV (0);
1141 GvSV (irsgv) = newSVpvn ("\n", 1); sv_magic (GvSV (irsgv), (SV *)irsgv, PERL_MAGIC_sv, "/", 0); 1142 GvSV (irsgv) = newSVpvn ("\n", 1); sv_magic (GvSV (irsgv), (SV *)irsgv, PERL_MAGIC_sv, "/", 0);
1142 GvHV (PL_hintgv) = 0; 1143 GvHV (PL_hintgv) = newHV ();
1144#if PERL_VERSION_ATLEAST (5,10,0)
1145 hv_magic (GvHV (PL_hintgv), 0, PERL_MAGIC_hints);
1146#endif
1143 PL_rs = newSVsv (GvSV (irsgv)); 1147 PL_rs = newSVsv (GvSV (irsgv));
1144 PL_defoutgv = (GV *)SvREFCNT_inc_NN (stdoutgv); 1148 PL_defoutgv = (GV *)SvREFCNT_inc_NN (stdoutgv);
1145 1149
1146 { 1150 {
1147 dSP; 1151 dSP;
1916 /* nothing to schedule: call the idle handler */ 1920 /* nothing to schedule: call the idle handler */
1917 if (SvROK (sv_idle) 1921 if (SvROK (sv_idle)
1918 && SvOBJECT (SvRV (sv_idle))) 1922 && SvOBJECT (SvRV (sv_idle)))
1919 { 1923 {
1920 if (SvRV (sv_idle) == SvRV (coro_current)) 1924 if (SvRV (sv_idle) == SvRV (coro_current))
1925 {
1926 require_pv ("Carp");
1927
1928 {
1929 dSP;
1930
1931 ENTER;
1932 SAVETMPS;
1933
1934 PUSHMARK (SP);
1921 croak ("FATAL: $Coro::IDLE blocked itself - did you try to block inside an event loop callback? Caught"); 1935 XPUSHs (sv_2mortal (newSVpv ("FATAL: $Coro::IDLE blocked itself - did you try to block inside an event loop callback? Caught", 0)));
1936 PUTBACK;
1937 call_pv ("Carp::confess", G_VOID | G_DISCARD);
1938
1939 FREETMPS;
1940 LEAVE;
1941 }
1942 }
1922 1943
1923 ++coro_nready; /* hack so that api_ready doesn't invoke ready hook */ 1944 ++coro_nready; /* hack so that api_ready doesn't invoke ready hook */
1924 api_ready (aTHX_ SvRV (sv_idle)); 1945 api_ready (aTHX_ SvRV (sv_idle));
1925 --coro_nready; 1946 --coro_nready;
1926 } 1947 }
2230 slf_init_terminate_cancel_common (aTHX_ frame, coro_hv); 2251 slf_init_terminate_cancel_common (aTHX_ frame, coro_hv);
2231 } 2252 }
2232 else 2253 else
2233 { 2254 {
2234 struct coro *self = SvSTATE_current; 2255 struct coro *self = SvSTATE_current;
2256
2257 if (!self)
2258 croak ("Coro::cancel called outside of thread content,");
2235 2259
2236 /* otherwise we cancel directly, purely for speed reasons 2260 /* otherwise we cancel directly, purely for speed reasons
2237 * unfortunately, this requires some magic trickery, as 2261 * unfortunately, this requires some magic trickery, as
2238 * somebody else could cancel us, so we have to fight the cancellation. 2262 * somebody else could cancel us, so we have to fight the cancellation.
2239 * this is ugly, and hopefully fully worth the extra speed. 2263 * this is ugly, and hopefully fully worth the extra speed.
2581 2605
2582/* "undo"/cancel a running slf call - used when cancelling a coro, mainly */ 2606/* "undo"/cancel a running slf call - used when cancelling a coro, mainly */
2583static void 2607static void
2584slf_destroy (pTHX_ struct coro *coro) 2608slf_destroy (pTHX_ struct coro *coro)
2585{ 2609{
2586 /* this callback is reserved for slf functions needing to do cleanup */ 2610 struct CoroSLF frame = coro->slf_frame;
2587 if (coro->slf_frame.destroy && coro->slf_frame.prepare && !PL_dirty)
2588 coro->slf_frame.destroy (aTHX_ &coro->slf_frame);
2589 2611
2590 /* 2612 /*
2591 * The on_destroy above most likely is from an SLF call. 2613 * The on_destroy below most likely is from an SLF call.
2592 * Since by definition the SLF call will not finish when we destroy 2614 * Since by definition the SLF call will not finish when we destroy
2593 * the coro, we will have to force-finish it here, otherwise 2615 * the coro, we will have to force-finish it here, otherwise
2594 * cleanup functions cannot call SLF functions. 2616 * cleanup functions cannot call SLF functions.
2595 */ 2617 */
2596 coro->slf_frame.prepare = 0; 2618 coro->slf_frame.prepare = 0;
2619
2620 /* this callback is reserved for slf functions needing to do cleanup */
2621 if (frame.destroy && frame.prepare && !PL_dirty)
2622 frame.destroy (aTHX_ &frame);
2597} 2623}
2598 2624
2599/* 2625/*
2600 * these not obviously related functions are all rolled into one 2626 * these not obviously related functions are all rolled into one
2601 * function to increase chances that they all will call transfer with the same 2627 * function to increase chances that they all will call transfer with the same
2941{ 2967{
2942 AV *av = (AV *)frame->data; 2968 AV *av = (AV *)frame->data;
2943 SV *count_sv = AvARRAY (av)[0]; 2969 SV *count_sv = AvARRAY (av)[0];
2944 SV *coro_hv = SvRV (coro_current); 2970 SV *coro_hv = SvRV (coro_current);
2945 2971
2972 frame->destroy = 0;
2973
2946 /* if we are about to throw, don't actually acquire the lock, just throw */ 2974 /* if we are about to throw, don't actually acquire the lock, just throw */
2947 if (CORO_THROW) 2975 if (ecb_expect_false (CORO_THROW))
2976 {
2977 /* we still might be responsible for the semaphore, so wake up others */
2978 coro_semaphore_adjust (aTHX_ av, 0);
2979
2948 return 0; 2980 return 0;
2981 }
2949 else if (SvIVX (count_sv) > 0) 2982 else if (SvIVX (count_sv) > 0)
2950 { 2983 {
2951 frame->destroy = 0;
2952
2953 if (acquire) 2984 if (acquire)
2954 SvIVX (count_sv) = SvIVX (count_sv) - 1; 2985 SvIVX (count_sv) = SvIVX (count_sv) - 1;
2955 else 2986 else
2956 coro_semaphore_adjust (aTHX_ av, 0); 2987 coro_semaphore_adjust (aTHX_ av, 0);
2957 2988
3417 3448
3418PROTOTYPES: DISABLE 3449PROTOTYPES: DISABLE
3419 3450
3420BOOT: 3451BOOT:
3421{ 3452{
3453#define VARx(name,expr,type) if (sizeof (type) < sizeof (expr)) croak ("FATAL: Coro thread context slot '" # name "' too small for this version of perl.");
3454#include "state.h"
3422#ifdef USE_ITHREADS 3455#ifdef USE_ITHREADS
3423# if CORO_PTHREAD 3456# if CORO_PTHREAD
3424 coro_thx = PERL_GET_CONTEXT; 3457 coro_thx = PERL_GET_CONTEXT;
3425# endif 3458# endif
3426#endif 3459#endif

Diff Legend

Removed lines
+ Added lines
< Changed lines
> Changed lines