diff options
author | Malcolm Beattie <mbeattie@sable.ox.ac.uk> | 1998-02-27 18:06:41 +0000 |
---|---|---|
committer | Malcolm Beattie <mbeattie@sable.ox.ac.uk> | 1998-02-27 18:06:41 +0000 |
commit | dce16143c60882f40eb787063b9483c00bb82139 (patch) | |
tree | dcb3c30695829781cc03b666fe1d2ae5eeda975c /sv.c | |
parent | d22150111e6fba142fe332ab0f2c6233df82013c (diff) | |
download | perl-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.c | 7 |
1 files changed, 5 insertions, 2 deletions
@@ -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)) { |