# endif
#endif
+Arp |SV* |lock |SV *sv
+
#if defined(PERL_OBJECT)
};
#endif
Perl_ptr_table_store
Perl_ptr_table_split
Perl_sys_intern_init
+Perl_lock
*/
varstash = GvSTASH(CvGV(cv));
vargv = *(GV**)hv_fetch(varstash, autoload, autolen, TRUE);
+ ENTER;
+ Perl_lock(aTHX_ (SV *)varstash);
if (!isGV(vargv))
gv_init(vargv, varstash, autoload, autolen, FALSE);
+ LEAVE;
varsv = GvSV(vargv);
+ Perl_lock(aTHX_ varsv);
sv_setpv(varsv, HvNAME(stash));
sv_catpvn(varsv, "::", 2);
sv_catpvn(varsv, name, len);
#if defined(USE_ITHREADS)
PERLVAR(Iptr_table, PTR_TBL_t*)
#endif
+
+#if defined(USE_THREADS)
+PERLVAR(Isv_lock_mutex, perl_mutex) /* Mutex for SvLOCK macro */
+#endif
PERLVARI(Ibeginav_save, AV*, Nullav) /* save BEGIN{}s when compiling */
PERLVAR(Inullstash, HV *) /* illegal symbols end up here */
# endif /* EMULATE_ATOMIC_REFCOUNTS */
MUTEX_INIT(&PL_cred_mutex);
+ MUTEX_INIT(&PL_sv_lock_mutex);
thr = init_main_thread();
#endif /* USE_THREADS */
dTOPss;
SV *retsv = sv;
#ifdef USE_THREADS
- MAGIC *mg;
-
- if (SvROK(sv))
- sv = SvRV(sv);
-
- mg = condpair_magic(sv);
- MUTEX_LOCK(MgMUTEXP(mg));
- if (MgOWNER(mg) == thr)
- MUTEX_UNLOCK(MgMUTEXP(mg));
- else {
- while (MgOWNER(mg))
- COND_WAIT(MgOWNERCONDP(mg), MgMUTEXP(mg));
- MgOWNER(mg) = thr;
- DEBUG_S(PerlIO_printf(Perl_debug_log, "0x%"UVxf": pp_lock lock 0x%"UVxf"\n",
- PTR2UV(thr), PTR2UV(sv));)
- MUTEX_UNLOCK(MgMUTEXP(mg));
- SAVEDESTRUCTOR_X(Perl_unlock_condpair, sv);
- }
+ Perl_lock(aTHX_ sv);
#endif /* USE_THREADS */
if (SvTYPE(retsv) == SVt_PVAV || SvTYPE(retsv) == SVt_PVHV
|| SvTYPE(retsv) == SVt_PVCV) {
PL_secondgv = gv_fetchpv("b", TRUE, SVt_PV);
PL_sortstash = stash;
}
+#ifdef USE_THREADS
+ Perl_lock(aTHX_ (SV *)PL_firstgv);
+ Perl_lock(aTHX_ (SV *)PL_secondgv);
+#endif
SAVESPTR(GvSV(PL_firstgv));
SAVESPTR(GvSV(PL_secondgv));
}
# endif
#endif
+PERL_CALLCONV SV* Perl_lock(pTHX_ SV *sv) __attribute__((noreturn));
+
#if defined(PERL_OBJECT)
};
#endif
#ifdef USE_THREADS
-# ifdef EMULATE_ATOMIC_REFCOUNTS
-# define ATOMIC_INC(count) STMT_START { \
- MUTEX_LOCK(&PL_svref_mutex); \
- ++count; \
- MUTEX_UNLOCK(&PL_svref_mutex); \
- } STMT_END
-# define ATOMIC_DEC_AND_TEST(res,count) STMT_START { \
- MUTEX_LOCK(&PL_svref_mutex); \
- res = (--count == 0); \
- MUTEX_UNLOCK(&PL_svref_mutex); \
- } STMT_END
-# else
-# define ATOMIC_INC(count) atomic_inc(&count)
-# define ATOMIC_DEC_AND_TEST(res,count) (res = atomic_dec_and_test(&count))
-# endif /* EMULATE_ATOMIC_REFCOUNTS */
+# if defined(VMS)
+# define ATOMIC_INC(count) __ATOMIC_INCREMENT_LONG(&count)
+# define ATOMIC_DEC_AND_TEST(res,count) res=(1==__ATOMIC_DECREMENT_LONG(&count))
+ # else
+# ifdef EMULATE_ATOMIC_REFCOUNTS
+ # define ATOMIC_INC(count) STMT_START { \
+ MUTEX_LOCK(&PL_svref_mutex); \
+ ++count; \
+ MUTEX_UNLOCK(&PL_svref_mutex); \
+ } STMT_END
+# define ATOMIC_DEC_AND_TEST(res,count) STMT_START { \
+ MUTEX_LOCK(&PL_svref_mutex); \
+ res = (--count == 0); \
+ MUTEX_UNLOCK(&PL_svref_mutex); \
+ } STMT_END
+# else
+# define ATOMIC_INC(count) atomic_inc(&count)
+# define ATOMIC_DEC_AND_TEST(res,count) (res = atomic_dec_and_test(&count))
+# endif /* EMULATE_ATOMIC_REFCOUNTS */
+# endif /* VMS */
#else
# define ATOMIC_INC(count) (++count)
# define ATOMIC_DEC_AND_TEST(res, count) (res = (--count == 0))
})
#else
# if defined(CRIPPLED_CC) || defined(USE_THREADS)
-# define SvREFCNT_inc(sv) sv_newref((SV*)sv)
+# if defined(VMS) && defined(__ALPHA)
+# define SvREFCNT_inc(sv) \
+ (PL_Sv=(SV*)(sv), (PL_Sv && __ATOMIC_INCREMENT_LONG(&(SvREFCNT(PL_Sv)))), (SV *)PL_Sv)
+# else
+# define SvREFCNT_inc(sv) sv_newref((SV*)sv)
+# endif
# else
# define SvREFCNT_inc(sv) \
((PL_Sv=(SV*)(sv)), (PL_Sv && ATOMIC_INC(SvREFCNT(PL_Sv))), (SV*)PL_Sv)
NUL character). Calls C<sv_grow> to perform the expansion if necessary.
Returns a pointer to the character buffer.
+=for apidoc Am|void|SvLOCK|SV* sv
+Aquires an internal mutex for a SV. Used to make sure multiple threads
+don't stomp on the guts of an SV at the same time
+
+=for apidoc Am|void|SvUNLOCK|SV* sv
+Release the internal mutex for an SV.
+
=cut
*/
SvSetSV_nosteal_and(dst,src,SvSETMAGIC(dst))
#ifdef DEBUGGING
+
+#define SvLOCK(sv) MUTEX_LOCK(&PL_sv_lock_mutex)
+#define SvUNLOCK(sv) MUTEX_UNLOCK(&PL_sv_lock_mutex)
#define SvPEEK(sv) sv_peek(sv)
#else
#define SvPEEK(sv) ""
return mg;
}
+SV *
+Perl_lock(pTHX_ SV *osv)
+{
+#ifdef USE_THREADS
+ MAGIC *mg;
+ SV *sv = osv;
+
+ SvLOCK(osv);
+ if (SvROK(sv)) {
+ sv = SvRV(sv);
+ SvUNLOCK(osv);
+ SvLOCK(sv);
+ }
+
+ mg = condpair_magic(sv);
+ MUTEX_LOCK(MgMUTEXP(mg));
+ if (MgOWNER(mg) == thr)
+ MUTEX_UNLOCK(MgMUTEXP(mg));
+ else {
+ while (MgOWNER(mg))
+ COND_WAIT(MgOWNERCONDP(mg), MgMUTEXP(mg));
+ MgOWNER(mg) = thr;
+ DEBUG_S(PerlIO_printf(Perl_debug_log, "0x%"UVxf": pp_lock lock 0x%"UVxf"\n",
+ PTR2UV(thr), PTR2UV(sv));)
+ MUTEX_UNLOCK(MgMUTEXP(mg));
+ SAVEDESTRUCTOR_X(Perl_unlock_condpair, sv);
+ }
+#endif
+ SvUNLOCK(sv);
+ return sv;
+}
+
/*
* Make a new perl thread structure using t as a prototype. Some of the
* fields for the new thread are copied from the prototype thread, t,