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.16 by root, Sun Jan 24 04:20:49 2016 UTC vs.
Revision 1.21 by root, Sun Aug 26 15:30:55 2018 UTC

1/* most win32 perls are beyond fixing, requiring dTHX */
2/* even for ISO-C functions such as malloc. avoid! avoid! avoid! */
3/* and fail to define numerous symbols, but still overrwide them */
4/* with non-working versions (e.g. setjmp). */
5#ifdef _WIN32
6/*# define PERL_CORE 1 fixes some, breaks others */
7#else
1#define PERL_NO_GET_CONTEXT 8# define PERL_NO_GET_CONTEXT
9#endif
2 10
3#include "EXTERN.h" 11#include "EXTERN.h"
4#include "perl.h" 12#include "perl.h"
5#include "XSUB.h" 13#include "XSUB.h"
6 14
10#include "perlmulticore.h" 18#include "perlmulticore.h"
11#include "schmorp.h" 19#include "schmorp.h"
12#include "xthread.h" 20#include "xthread.h"
13 21
14#ifdef _WIN32 22#ifdef _WIN32
15 typedef char sigset_t; 23 #ifndef sigset_t
16 #define pthread_sigmask(mode,new,old) 24 #define sigset_t int
25 #endif
17#endif 26#endif
18 27
19#ifndef SvREFCNT_dec_NN 28#ifndef SvREFCNT_dec_NN
20 #define SvREFCNT_dec_NN(sv) SvREFCNT_dec (sv) 29 #define SvREFCNT_dec_NN(sv) SvREFCNT_dec (sv)
21#endif 30#endif
114X_THREAD_PROC(thread_proc) 123X_THREAD_PROC(thread_proc)
115{ 124{
116 PERL_SET_CONTEXT (perl_thx); 125 PERL_SET_CONTEXT (perl_thx);
117 126
118 { 127 {
119 dTHX; /* inefficient, we already have perl_thx, but I see no better way */ 128 dTHXa (perl_thx);
120 dJMPENV; 129 dJMPENV;
121 struct tctx *ctx; 130 struct tctx *ctx;
122 int catchret; 131 int catchret;
123 132
124 X_LOCK (release_m); 133 X_LOCK (release_m);
193 X_TLS_SET (current_key, 0); 202 X_TLS_SET (current_key, 0);
194 return; 203 return;
195 } 204 }
196 205
197 struct tctx *ctx = tctx_get (); 206 struct tctx *ctx = tctx_get ();
198 ctx->coro = SvREFCNT_inc_NN (CORO_CURRENT); 207 ctx->coro = SvREFCNT_inc_simple_NN (CORO_CURRENT);
199 ctx->wait_f = 0; 208 ctx->wait_f = 0;
200 209
201 X_TLS_SET (current_key, ctx); 210 X_TLS_SET (current_key, ctx);
202 pthread_sigmask (SIG_SETMASK, &fullsigset, &cursigset); 211 pthread_sigmask (SIG_SETMASK, &fullsigset, &cursigset);
203 212
246 jeret = ctx->jeret; 255 jeret = ctx->jeret;
247 tctx_put (ctx); 256 tctx_put (ctx);
248 pthread_sigmask (SIG_SETMASK, &cursigset, 0); 257 pthread_sigmask (SIG_SETMASK, &cursigset, 0);
249 258
250 if (jeret) 259 if (jeret)
260 {
261 dTHX;
251 JMPENV_JUMP (jeret); 262 JMPENV_JUMP (jeret);
263 }
252} 264}
253 265
254static void 266static void
255set_thread_enable (pTHX_ void *arg) 267set_thread_enable (pTHX_ void *arg)
256{ 268{
348 360
349void 361void
350sleep (NV seconds) 362sleep (NV seconds)
351 CODE: 363 CODE:
352 perlinterp_release (); 364 perlinterp_release ();
353 usleep (seconds * 1e6); 365 {
366 int nsec = seconds;
367 if (nsec) sleep (nsec);
368 nsec = (seconds - nsec) * 1e9;
369 if (nsec) usleep (nsec);
370 }
354 perlinterp_acquire (); 371 perlinterp_acquire ();
355 372

Diff Legend

Removed lines
+ Added lines
< Changed lines
> Changed lines