summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
-rw-r--r--mg.c1
-rw-r--r--op.c2
-rw-r--r--opcode.h2
-rwxr-xr-xopcode.pl2
-rw-r--r--pp.c9
-rw-r--r--pp_hot.c1
6 files changed, 13 insertions, 4 deletions
diff --git a/mg.c b/mg.c
index dedf381629..7f49f68aa0 100644
--- a/mg.c
+++ b/mg.c
@@ -1723,6 +1723,7 @@ MAGIC *mg;
croak("panic: magic_mutexfree");
MUTEX_DESTROY(MgMUTEXP(mg));
COND_DESTROY(MgCONDP(mg));
+ SvREFCNT_dec(sv);
return 0;
}
#endif /* USE_THREADS */
diff --git a/op.c b/op.c
index 680b825865..f9449f50d1 100644
--- a/op.c
+++ b/op.c
@@ -1288,7 +1288,7 @@ I32 type;
switch (o->op_type) {
case OP_ENTERSUB:
- if ((type == OP_DEFINED) &&
+ if ((type == OP_DEFINED || type == OP_LOCK) &&
!(o->op_flags & OPf_STACKED)) {
o->op_type = OP_RV2CV; /* entersub => rv2cv */
o->op_ppaddr = ppaddr[OP_RV2CV];
diff --git a/opcode.h b/opcode.h
index 7cf7f66800..1b465ddb30 100644
--- a/opcode.h
+++ b/opcode.h
@@ -2137,7 +2137,7 @@ EXT OP * (*check[]) _((OP *op)) = {
ck_null, /* egrent */
ck_null, /* getlogin */
ck_fun, /* syscall */
- ck_null, /* lock */
+ ck_rfun, /* lock */
};
#endif
diff --git a/opcode.pl b/opcode.pl
index fb3accc307..f8a7bb7787 100755
--- a/opcode.pl
+++ b/opcode.pl
@@ -654,4 +654,4 @@ getlogin getlogin ck_null st
syscall syscall ck_fun imst S L
# For multi-threading
-lock lock ck_null s S
+lock lock ck_rfun s S
diff --git a/pp.c b/pp.c
index d002a1f0c5..649506fa89 100644
--- a/pp.c
+++ b/pp.c
@@ -4266,8 +4266,9 @@ void *svv;
PP(pp_lock)
{
dSP;
-#ifdef USE_THREADS
dTOPss;
+ SV *retsv = sv;
+#ifdef USE_THREADS
MAGIC *mg;
if (SvROK(sv))
@@ -4284,8 +4285,14 @@ PP(pp_lock)
DEBUG_L(PerlIO_printf(PerlIO_stderr(), "0x%lx: pp_lock lock 0x%lx\n",
(unsigned long)thr, (unsigned long)sv);)
MUTEX_UNLOCK(MgMUTEXP(mg));
+ SvREFCNT_inc(sv); /* keep alive until magic_mutexfree */
save_destructor(unlock_condpair, sv);
}
#endif /* USE_THREADS */
+ if (SvTYPE(retsv) == SVt_PVAV || SvTYPE(retsv) == SVt_PVHV
+ || SvTYPE(retsv) == SVt_PVCV) {
+ retsv = refto(retsv);
+ }
+ SETs(retsv);
RETURN;
}
diff --git a/pp_hot.c b/pp_hot.c
index c19e928f67..bc46cca740 100644
--- a/pp_hot.c
+++ b/pp_hot.c
@@ -1866,6 +1866,7 @@ PP(pp_entersub)
DEBUG_L(PerlIO_printf(PerlIO_stderr(), "%p: pp_entersub lock %p\n",
thr, sv);)
MUTEX_UNLOCK(MgMUTEXP(mg));
+ SvREFCNT_inc(sv); /* Keep alive until magic_mutexfree */
save_destructor(unlock_condpair, sv);
}
MUTEX_LOCK(CvMUTEXP(cv));