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

Comparing Coro-Multicore/Multicore.xs (file contents):
Revision 1.21 by root, Sun Aug 26 15:30:55 2018 UTC vs.
Revision 1.27 by root, Mon Dec 9 03:12:23 2019 UTC

27 27
28#ifndef SvREFCNT_dec_NN 28#ifndef SvREFCNT_dec_NN
29 #define SvREFCNT_dec_NN(sv) SvREFCNT_dec (sv) 29 #define SvREFCNT_dec_NN(sv) SvREFCNT_dec (sv)
30#endif 30#endif
31 31
32#ifndef SvREFCNT_dec_simple_void_NN
33 #define SvREFCNT_dec_simple_void_NN(sv) SvREFCNT_dec (sv)
34#endif
35
32#ifndef SvREFCNT_inc_NN 36#ifndef SvREFCNT_inc_NN
33 #define SvREFCNT_inc_NN(sv) SvREFCNT_inc (sv) 37 #define SvREFCNT_inc_NN(sv) SvREFCNT_inc (sv)
34#endif 38#endif
35 39
40#ifndef RECURSION_CHECK
36#define RECURSION_CHECK 0 41 #define RECURSION_CHECK 0
42#endif
37 43
38static X_TLS_DECLARE(current_key); 44static X_TLS_DECLARE(current_key);
39#if RECURSION_CHECK 45#if RECURSION_CHECK
40static X_TLS_DECLARE(check_key); 46static X_TLS_DECLARE(check_key);
41#endif 47#endif
42 48
49static void
50fatal (const char *msg)
51{
52 write (2, msg, strlen (msg));
53 abort ();
54}
43 55
44static s_epipe ep; 56static s_epipe ep;
45static void *perl_thx; 57static void *perl_thx;
46static sigset_t cursigset, fullsigset; 58static sigset_t cursigset, fullsigset;
47 59
177static void 189static void
178start_thread (void) 190start_thread (void)
179{ 191{
180 xthread_t tid; 192 xthread_t tid;
181 193
194 if (!curthreads)
195 {
196 X_UNLOCK (release_m);
197 {
198 dTHX;
199 eval_pv ("Coro::Multicore::init", 1);
200 }
201 X_LOCK (release_m);
202 }
203
182 if (curthreads >= max_threads && 0) 204 if (curthreads >= max_threads && 0)
183 return; 205 return;
184 206
185 ++curthreads; 207 ++curthreads;
186 ++idle; 208 ++idle;
188} 210}
189 211
190static void 212static void
191pmapi_release (void) 213pmapi_release (void)
192{ 214{
215 if (! ((thread_enable ? thread_enable : global_enable) & 1))
216 {
217 X_TLS_SET (current_key, 0);
218 return;
219 }
220
193 #if RECURSION_CHECK 221 #if RECURSION_CHECK
194 if (X_TLS_GET (check_key)) 222 if (X_TLS_GET (check_key))
195 croak ("perlinterp_release () called without valid perl context"); 223 fatal ("FATAL: perlinterp_release () called without valid perl context");
196 224
197 X_TLS_SET (check_key, &check_key); 225 X_TLS_SET (check_key, &check_key);
198 #endif 226 #endif
199
200 if (! ((thread_enable ? thread_enable : global_enable) & 1))
201 {
202 X_TLS_SET (current_key, 0);
203 return;
204 }
205 227
206 struct tctx *ctx = tctx_get (); 228 struct tctx *ctx = tctx_get ();
207 ctx->coro = SvREFCNT_inc_simple_NN (CORO_CURRENT); 229 ctx->coro = SvREFCNT_inc_simple_NN (CORO_CURRENT);
208 ctx->wait_f = 0; 230 ctx->wait_f = 0;
209 231
231pmapi_acquire (void) 253pmapi_acquire (void)
232{ 254{
233 int jeret; 255 int jeret;
234 struct tctx *ctx = X_TLS_GET (current_key); 256 struct tctx *ctx = X_TLS_GET (current_key);
235 257
258 if (!ctx)
259 return;
260
236 #if RECURSION_CHECK 261 #if RECURSION_CHECK
237 if (X_TLS_GET (check_key) != &check_key) 262 if (X_TLS_GET (check_key) != &check_key)
238 croak ("perlinterp_acquire () called with valid perl context"); 263 fatal ("FATAL: perlinterp_acquire () called with valid perl context");
239 264
240 X_TLS_SET (check_key, 0); 265 X_TLS_SET (check_key, 0);
241 #endif 266 #endif
242
243 if (!ctx)
244 return;
245 267
246 X_LOCK (acquire_m); 268 X_LOCK (acquire_m);
247 269
248 tctxs_put (&acquirers, ctx); 270 tctxs_put (&acquirers, ctx);
249 271
289 311
290 perl_thx = PERL_GET_CONTEXT; 312 perl_thx = PERL_GET_CONTEXT;
291 313
292 I_CORO_API ("Coro::Multicore"); 314 I_CORO_API ("Coro::Multicore");
293 315
316 if (0) { /*D*/
294 X_LOCK (release_m); 317 X_LOCK (release_m);
295 while (idle < min_idle) 318 while (idle < min_idle)
296 start_thread (); 319 start_thread ();
297 X_UNLOCK (release_m); 320 X_UNLOCK (release_m);
321 }
298 322
299 /* not perfectly efficient to do it this way, but it is simple */ 323 /* not perfectly efficient to do it this way, but it is simple */
300 perl_multicore_init (); /* calls release */ 324 perl_multicore_init (); /* calls release */
301 perl_multicore_api->pmapi_release = pmapi_release; 325 perl_multicore_api->pmapi_release = pmapi_release;
302 perl_multicore_api->pmapi_acquire = pmapi_acquire; 326 perl_multicore_api->pmapi_acquire = pmapi_acquire;
322scoped_disable () 346scoped_disable ()
323 CODE: 347 CODE:
324 LEAVE; /* see Guard.xs */ 348 LEAVE; /* see Guard.xs */
325 CORO_ENTERLEAVE_SCOPE_HOOK (set_thread_enable, (void *)2, set_thread_enable, (void *)0); 349 CORO_ENTERLEAVE_SCOPE_HOOK (set_thread_enable, (void *)2, set_thread_enable, (void *)0);
326 ENTER; /* see Guard.xs */ 350 ENTER; /* see Guard.xs */
351
352#if 0
327 353
328U32 354U32
329min_idle_threads (U32 min = NO_INIT) 355min_idle_threads (U32 min = NO_INIT)
330 CODE: 356 CODE:
331 X_LOCK (acquire_m); 357 X_LOCK (acquire_m);
333 if (items) 359 if (items)
334 min_idle = min; 360 min_idle = min;
335 X_UNLOCK (acquire_m); 361 X_UNLOCK (acquire_m);
336 OUTPUT: 362 OUTPUT:
337 RETVAL 363 RETVAL
338 364
365#endif
339 366
340int 367int
341fd () 368fd ()
342 CODE: 369 CODE:
343 RETVAL = s_epipe_fd (&ep); 370 RETVAL = s_epipe_fd (&ep);
351 X_LOCK (acquire_m); 378 X_LOCK (acquire_m);
352 while (acquirers.cur) 379 while (acquirers.cur)
353 { 380 {
354 struct tctx *ctx = tctxs_get (&acquirers); 381 struct tctx *ctx = tctxs_get (&acquirers);
355 CORO_READY ((SV *)ctx->coro); 382 CORO_READY ((SV *)ctx->coro);
356 SvREFCNT_dec_NN ((SV *)ctx->coro); 383 SvREFCNT_dec_simple_void_NN ((SV *)ctx->coro);
357 ctx->coro = 0; 384 ctx->coro = 0;
358 } 385 }
359 X_UNLOCK (acquire_m); 386 X_UNLOCK (acquire_m);
360 387
361void 388void

Diff Legend

Removed lines
+ Added lines
< Changed lines
> Changed lines