SV *sv;
PerlLIO_dup2(PerlIO_fileno(fp), fd);
+ FDPID_LOCK();
sv = *av_fetch(PL_fdpid,PerlIO_fileno(fp),TRUE);
(void)SvUPGRADE(sv, SVt_IV);
pid = SvIVX(sv);
SvIVX(sv) = 0;
sv = *av_fetch(PL_fdpid,fd,TRUE);
+ FDPID_UNLOCK();
(void)SvUPGRADE(sv, SVt_IV);
SvIVX(sv) = pid;
if (!was_fdopen)
/* subprocess state */
PERLVAR(Ifdpid, AV *) /* keep fd-to-pid mappings for my_popen */
+#ifdef USE_THREADS
+PERLVAR(Ifdpid_mutex, perl_mutex) /* mutex for fdpid array */
+#endif
+
/* internal state */
PERLVAR(Itainting, bool) /* doing taint checks */
PERLVARI(Iop_mask, char *, NULL) /* masked operations for safe evals */
MUTEX_INIT(&PL_cred_mutex);
MUTEX_INIT(&PL_sv_lock_mutex);
+ MUTEX_INIT(&PL_fdpid_mutex);
thr = init_main_thread();
#endif /* USE_THREADS */
MUTEX_DESTROY(&PL_sv_mutex);
MUTEX_DESTROY(&PL_eval_mutex);
MUTEX_DESTROY(&PL_cred_mutex);
+ MUTEX_DESTROY(&PL_fdpid_mutex);
COND_DESTROY(&PL_eval_cond);
#ifdef EMULATE_ATOMIC_REFCOUNTS
MUTEX_DESTROY(&PL_svref_mutex);
#define SvGROW(sv,len) (SvLEN(sv) < (len) ? sv_grow(sv,len) : SvPVX(sv))
#define Sv_Grow sv_grow
+
+#ifdef USE_THREADS
+# define FDPID_LOCK() MUTEX_LOCK(&PL_fdpid_mutex)
+# define FDPID_UNLOCK() MUTEX_UNLOCK(&PL_fdpid_mutex)
+#else
+# define FDPID_LOCK()
+# define FDPID_UNLOCK()
+#endif
PerlLIO_close(p[This]);
p[This] = p[that];
}
+ FDPID_LOCK();
sv = *av_fetch(PL_fdpid,p[This],TRUE);
+ FDPID_UNLOCK();
(void)SvUPGRADE(sv,SVt_IV);
SvIVX(sv) = pid;
PL_forkprocess = pid;
int saved_win32_errno;
#endif
+ FDPID_LOCK();
svp = av_fetch(PL_fdpid,PerlIO_fileno(ptr),TRUE);
+ FDPID_UNLOCK();
pid = SvIVX(*svp);
SvREFCNT_dec(*svp);
*svp = &PL_sv_undef;
/* be used by my_pclose */
/*---------------------------------------------*/
close(fd);
+ FDPID_LOCK();
p_sv = av_fetch(PL_fdpid,fd,TRUE);
fd = (int) SvIVX(*p_sv);
SvREFCNT_dec(*p_sv);
*p_sv = &PL_sv_undef;
sv = *av_fetch(PL_fdpid,fd,TRUE);
+ FDPID_UNLOCK();
(void) SvUPGRADE(sv, SVt_IV);
SvIVX(sv) = pid;
status = 0;
Perl_stdin_fd = pFd[that];
if (strNE(cmd,"-"))
{
- PERL_FLUSHALL_FOR_CHILD;
+ PERL_FLUSHALL_FOR_CHILD;
pid = spawn_cmd(cmd, Perl_stdin_fd, Perl_stdout_fd);
if (pid >= 0)
{
+ FDPID_LOCK();
sv = *av_fetch(PL_fdpid,pFd[this],TRUE);
+ FDPID_UNLOCK();
(void) SvUPGRADE(sv, SVt_IV);
SvIVX(sv) = pid;
fd = PerlIO_fdopen(pFd[this], mode);
}
else
{
+ FDPID_LOCK();
sv = *av_fetch(PL_fdpid,pFd[that],TRUE);
+ FDPID_UNLOCK();
(void) SvUPGRADE(sv, SVt_IV);
SvIVX(sv) = pFd[this];
fd = PerlIO_fdopen(pFd[this], mode);
SV **sv;
FILE *other;
+ FDPID_LOCK();
sv = av_fetch(PL_fdpid,PerlIO_fileno(fp),TRUE);
+ FDPID_UNLOCK();
pid = (int) SvIVX(*sv);
SvREFCNT_dec(*sv);
*sv = &PL_sv_undef;
/* close saved handle */
win32_close(oldfd);
+ FDPID_LOCK();
sv_setiv(*av_fetch(w32_fdpid, p[parent], TRUE), childpid);
+ FDPID_UNLOCK();
/* set process id so that it can be returned by perl's open() */
PL_forkprocess = childpid;
int childpid, status;
SV *sv;
+ FDPID_LOCK();
sv = *av_fetch(w32_fdpid, win32_fileno(pf), TRUE);
+ FDPID_UNLOCK();
if (SvIOK(sv))
childpid = SvIVX(sv);
else