summaryrefslogtreecommitdiff
path: root/sv.c
diff options
context:
space:
mode:
authorMalcolm Beattie <mbeattie@sable.ox.ac.uk>1998-02-27 18:06:41 +0000
committerMalcolm Beattie <mbeattie@sable.ox.ac.uk>1998-02-27 18:06:41 +0000
commitdce16143c60882f40eb787063b9483c00bb82139 (patch)
treedcb3c30695829781cc03b666fe1d2ae5eeda975c /sv.c
parentd22150111e6fba142fe332ab0f2c6233df82013c (diff)
downloadperl-dce16143c60882f40eb787063b9483c00bb82139.tar.gz
Make refcounts atomic for threading (dependent on appropriate
arch-dependent and compiler-dependent definitions in atomic.h or else falls back to a global mutex to protect refcounts). p4raw-id: //depot/perl@598
Diffstat (limited to 'sv.c')
-rw-r--r--sv.c7
1 files changed, 5 insertions, 2 deletions
diff --git a/sv.c b/sv.c
index 0edfdb2453..af74e28e0c 100644
--- a/sv.c
+++ b/sv.c
@@ -2870,13 +2870,15 @@ SV *
sv_newref(SV *sv)
{
if (sv)
- SvREFCNT(sv)++;
+ ATOMIC_INC(SvREFCNT(sv));
return sv;
}
void
sv_free(SV *sv)
{
+ int refcount_is_zero;
+
if (!sv)
return;
if (SvREADONLY(sv)) {
@@ -2891,7 +2893,8 @@ sv_free(SV *sv)
warn("Attempt to free unreferenced scalar");
return;
}
- if (--SvREFCNT(sv) > 0)
+ ATOMIC_DEC_AND_TEST(refcount_is_zero, SvREFCNT(sv));
+ if (!refcount_is_zero)
return;
#ifdef DEBUGGING
if (SvTEMP(sv)) {