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.49 by pcg, Sun Nov 23 03:34:13 2003 UTC vs.
Revision 1.50 by pcg, Sun Nov 30 16:59:15 2003 UTC

38# else 38# else
39# undef HAVE_MMAP 39# undef HAVE_MMAP
40# endif 40# endif
41# endif 41# endif
42#endif 42#endif
43
44#define MAY_FLUSH /* increases codesize and is rarely used */
45 43
46#define SUB_INIT "Coro::State::initialize" 44#define SUB_INIT "Coro::State::initialize"
47#define UCORO_STATE "_coro_state" 45#define UCORO_STATE "_coro_state"
48 46
49/* The next macro should declare a variable stacklevel that contains and approximation 47/* The next macro should declare a variable stacklevel that contains and approximation
226#endif 224#endif
227 225
228 return newpadlist; 226 return newpadlist;
229} 227}
230 228
231#ifdef MAY_FLUSH
232STATIC void 229STATIC void
233free_padlist (AV *padlist) 230free_padlist (AV *padlist)
234{ 231{
235 /* may be during global destruction */ 232 /* may be during global destruction */
236 if (SvREFCNT(padlist)) 233 if (SvREFCNT (padlist))
237 { 234 {
238 I32 i = AvFILLp(padlist); 235 I32 i = AvFILLp (padlist);
239 while (i >= 0) 236 while (i >= 0)
240 { 237 {
241 SV **svp = av_fetch(padlist, i--, FALSE); 238 SV **svp = av_fetch (padlist, i--, FALSE);
242 SV *sv = svp ? *svp : Nullsv;
243 if (sv) 239 if (svp)
240 {
241 SV *sv;
242 while (&PL_sv_undef != (sv = av_pop ((AV *)*svp)))
244 SvREFCNT_dec(sv); 243 SvREFCNT_dec (sv);
244
245 SvREFCNT_dec (*svp);
246 }
245 } 247 }
246 248
247 SvREFCNT_dec((SV*)padlist); 249 SvREFCNT_dec ((SV*)padlist);
248 } 250 }
249} 251}
250#endif 252
253STATIC int
254coro_cv_free (SV *sv, MAGIC *mg)
255{
256 AV *padlist;
257 AV *av = (AV *)mg->mg_obj;
258
259 /* casting is fun. */
260 while (&PL_sv_undef != (SV *)(padlist = (AV *)av_pop (av)))
261 free_padlist (padlist);
262}
263
264#define PERL_MAGIC_coro PERL_MAGIC_ext
265
266static MGVTBL vtbl_coro = {0, 0, 0, 0, coro_cv_free};
251 267
252/* the next two functions merely cache the padlists */ 268/* the next two functions merely cache the padlists */
253STATIC void 269STATIC void
254get_padlist (CV *cv) 270get_padlist (CV *cv)
255{ 271{
256 SV **he = hv_fetch (padlist_cache, (void *)&cv, sizeof (CV *), 0); 272 MAGIC *mg = mg_find ((SV *)cv, PERL_MAGIC_coro);
257 273
258 if (he && AvFILLp ((AV *)*he) >= 0) 274 if (mg && AvFILLp ((AV *)mg->mg_obj) >= 0)
259 CvPADLIST (cv) = (AV *)av_pop ((AV *)*he); 275 CvPADLIST (cv) = (AV *)av_pop ((AV *)mg->mg_obj);
260 else 276 else
261 CvPADLIST (cv) = clone_padlist (CvPADLIST (cv)); 277 CvPADLIST (cv) = clone_padlist (CvPADLIST (cv));
262} 278}
263 279
264STATIC void 280STATIC void
265put_padlist (CV *cv) 281put_padlist (CV *cv)
266{ 282{
267 SV **he = hv_fetch (padlist_cache, (void *)&cv, sizeof (CV *), 1); 283 MAGIC *mg = mg_find ((SV *)cv, PERL_MAGIC_coro);
268 284
269 if (SvTYPE (*he) != SVt_PVAV) 285 if (!mg)
270 { 286 {
271 SvREFCNT_dec (*he); 287 sv_magic ((SV *)cv, 0, PERL_MAGIC_coro, 0, 0);
288 mg = mg_find ((SV *)cv, PERL_MAGIC_coro);
289 mg->mg_virtual = &vtbl_coro;
272 *he = (SV *)newAV (); 290 mg->mg_obj = (SV *)newAV ();
273 } 291 }
274 292
275 av_push ((AV *)*he, (SV *)CvPADLIST (cv)); 293 av_push ((AV *)mg->mg_obj, (SV *)CvPADLIST (cv));
276} 294}
277
278#ifdef MAY_FLUSH
279STATIC void
280flush_padlist_cache ()
281{
282 HV *hv = padlist_cache;
283 padlist_cache = newHV ();
284
285 if (hv_iterinit (hv))
286 {
287 HE *he;
288 AV *padlist;
289
290 while (!!(he = hv_iternext (hv)))
291 {
292 AV *av = (AV *)HeVAL(he);
293
294 /* casting is fun. */
295 while (&PL_sv_undef != (SV *)(padlist = (AV *)av_pop (av)))
296 free_padlist (padlist);
297 }
298 }
299
300 SvREFCNT_dec (hv);
301}
302#endif
303 295
304#define SB do { 296#define SB do {
305#define SE } while (0) 297#define SE } while (0)
306 298
307#define LOAD(state) load_state(aTHX_ (state)); 299#define LOAD(state) load_state(aTHX_ (state));
1010 deallocate_stack (coro); 1002 deallocate_stack (coro);
1011 SvREFCNT_dec (coro->args); 1003 SvREFCNT_dec (coro->args);
1012 Safefree (coro); 1004 Safefree (coro);
1013 1005
1014void 1006void
1015flush()
1016 CODE:
1017#ifdef MAY_FLUSH
1018 flush_padlist_cache ();
1019#endif
1020
1021void
1022_exit(code) 1007_exit(code)
1023 int code 1008 int code
1024 PROTOTYPE: $ 1009 PROTOTYPE: $
1025 CODE: 1010 CODE:
1026#if defined(__GLIBC__) || _POSIX_C_SOURCE 1011#if defined(__GLIBC__) || _POSIX_C_SOURCE
1096 sv_setiv(sv, (IV)&coroapi); 1081 sv_setiv(sv, (IV)&coroapi);
1097 SvREADONLY_on(sv); 1082 SvREADONLY_on(sv);
1098 } 1083 }
1099} 1084}
1100 1085
1086#if !PERL_MICRO
1087
1101void 1088void
1102ready(self) 1089ready(self)
1103 SV * self 1090 SV * self
1104 PROTOTYPE: $ 1091 PROTOTYPE: $
1105 CODE: 1092 CODE:
1106 api_ready (self); 1093 api_ready (self);
1094
1095#endif
1107 1096
1108int 1097int
1109nready(...) 1098nready(...)
1110 PROTOTYPE: 1099 PROTOTYPE:
1111 CODE: 1100 CODE:

Diff Legend

Removed lines
+ Added lines
< Changed lines
> Changed lines