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.444 by root, Thu May 1 08:09:18 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>
1916 /* nothing to schedule: call the idle handler */ 1917 /* nothing to schedule: call the idle handler */
1917 if (SvROK (sv_idle) 1918 if (SvROK (sv_idle)
1918 && SvOBJECT (SvRV (sv_idle))) 1919 && SvOBJECT (SvRV (sv_idle)))
1919 { 1920 {
1920 if (SvRV (sv_idle) == SvRV (coro_current)) 1921 if (SvRV (sv_idle) == SvRV (coro_current))
1922 {
1923 require_pv ("Carp");
1924
1925 {
1926 dSP;
1927
1928 ENTER;
1929 SAVETMPS;
1930
1931 PUSHMARK (SP);
1921 croak ("FATAL: $Coro::IDLE blocked itself - did you try to block inside an event loop callback? Caught"); 1932 XPUSHs (sv_2mortal (newSVpv ("FATAL: $Coro::IDLE blocked itself - did you try to block inside an event loop callback? Caught", 0)));
1933 PUTBACK;
1934 call_pv ("Carp::confess", G_VOID | G_DISCARD);
1935
1936 FREETMPS;
1937 LEAVE;
1938 }
1939 }
1922 1940
1923 ++coro_nready; /* hack so that api_ready doesn't invoke ready hook */ 1941 ++coro_nready; /* hack so that api_ready doesn't invoke ready hook */
1924 api_ready (aTHX_ SvRV (sv_idle)); 1942 api_ready (aTHX_ SvRV (sv_idle));
1925 --coro_nready; 1943 --coro_nready;
1926 } 1944 }
2230 slf_init_terminate_cancel_common (aTHX_ frame, coro_hv); 2248 slf_init_terminate_cancel_common (aTHX_ frame, coro_hv);
2231 } 2249 }
2232 else 2250 else
2233 { 2251 {
2234 struct coro *self = SvSTATE_current; 2252 struct coro *self = SvSTATE_current;
2253
2254 if (!self)
2255 croak ("Coro::cancel called outside of thread content,");
2235 2256
2236 /* otherwise we cancel directly, purely for speed reasons 2257 /* otherwise we cancel directly, purely for speed reasons
2237 * unfortunately, this requires some magic trickery, as 2258 * unfortunately, this requires some magic trickery, as
2238 * somebody else could cancel us, so we have to fight the cancellation. 2259 * somebody else could cancel us, so we have to fight the cancellation.
2239 * this is ugly, and hopefully fully worth the extra speed. 2260 * this is ugly, and hopefully fully worth the extra speed.
2581 2602
2582/* "undo"/cancel a running slf call - used when cancelling a coro, mainly */ 2603/* "undo"/cancel a running slf call - used when cancelling a coro, mainly */
2583static void 2604static void
2584slf_destroy (pTHX_ struct coro *coro) 2605slf_destroy (pTHX_ struct coro *coro)
2585{ 2606{
2586 /* this callback is reserved for slf functions needing to do cleanup */ 2607 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 2608
2590 /* 2609 /*
2591 * The on_destroy above most likely is from an SLF call. 2610 * The on_destroy below most likely is from an SLF call.
2592 * Since by definition the SLF call will not finish when we destroy 2611 * Since by definition the SLF call will not finish when we destroy
2593 * the coro, we will have to force-finish it here, otherwise 2612 * the coro, we will have to force-finish it here, otherwise
2594 * cleanup functions cannot call SLF functions. 2613 * cleanup functions cannot call SLF functions.
2595 */ 2614 */
2596 coro->slf_frame.prepare = 0; 2615 coro->slf_frame.prepare = 0;
2616
2617 /* this callback is reserved for slf functions needing to do cleanup */
2618 if (frame.destroy && frame.prepare && !PL_dirty)
2619 frame.destroy (aTHX_ &frame);
2597} 2620}
2598 2621
2599/* 2622/*
2600 * these not obviously related functions are all rolled into one 2623 * these not obviously related functions are all rolled into one
2601 * function to increase chances that they all will call transfer with the same 2624 * function to increase chances that they all will call transfer with the same
2941{ 2964{
2942 AV *av = (AV *)frame->data; 2965 AV *av = (AV *)frame->data;
2943 SV *count_sv = AvARRAY (av)[0]; 2966 SV *count_sv = AvARRAY (av)[0];
2944 SV *coro_hv = SvRV (coro_current); 2967 SV *coro_hv = SvRV (coro_current);
2945 2968
2969 frame->destroy = 0;
2970
2946 /* if we are about to throw, don't actually acquire the lock, just throw */ 2971 /* if we are about to throw, don't actually acquire the lock, just throw */
2947 if (CORO_THROW) 2972 if (ecb_expect_false (CORO_THROW))
2973 {
2974 /* we still might be responsible for the semaphore, so wake up others */
2975 coro_semaphore_adjust (aTHX_ av, 0);
2976
2948 return 0; 2977 return 0;
2978 }
2949 else if (SvIVX (count_sv) > 0) 2979 else if (SvIVX (count_sv) > 0)
2950 { 2980 {
2951 frame->destroy = 0;
2952
2953 if (acquire) 2981 if (acquire)
2954 SvIVX (count_sv) = SvIVX (count_sv) - 1; 2982 SvIVX (count_sv) = SvIVX (count_sv) - 1;
2955 else 2983 else
2956 coro_semaphore_adjust (aTHX_ av, 0); 2984 coro_semaphore_adjust (aTHX_ av, 0);
2957 2985
3417 3445
3418PROTOTYPES: DISABLE 3446PROTOTYPES: DISABLE
3419 3447
3420BOOT: 3448BOOT:
3421{ 3449{
3450#define VARx(name,expr,type) if (sizeof (type) < sizeof (expr)) croak ("FATAL: Coro thread context slot '" # name "' too small for this version of perl");
3451#include "state.h"
3422#ifdef USE_ITHREADS 3452#ifdef USE_ITHREADS
3423# if CORO_PTHREAD 3453# if CORO_PTHREAD
3424 coro_thx = PERL_GET_CONTEXT; 3454 coro_thx = PERL_GET_CONTEXT;
3425# endif 3455# endif
3426#endif 3456#endif

Diff Legend

Removed lines
+ Added lines
< Changed lines
> Changed lines