Fix threadcounts for arrays and hashes.
Artur Bergman [Thu, 25 Oct 2001 10:18:23 +0000 (10:18 +0000)]
p4raw-id: //depot/perl@12640

ext/threads/shared/shared.pm
ext/threads/shared/shared.xs

index 3fec356..d928d26 100644 (file)
@@ -63,6 +63,7 @@ sub CLONE {
 
 sub DESTROY {
     my $self = shift;
+    _thrcnt_dec($$self);
     delete($shared{$$self});
 }
 
index bbc6e6e..e2187d7 100644 (file)
@@ -99,7 +99,10 @@ SV*
 _thrcnt(ref)
         SV* ref
        CODE:
-        shared_sv* shared = Perl_sharedsv_find(aTHX, ref);
+        shared_sv* shared;
+       if(SvROK(ref))
+           ref = SvRV(ref);
+       shared = Perl_sharedsv_find(aTHX, ref);
         if(!shared)
            croak("thrcnt can only be used on shared values");
        SHAREDSvLOCK(shared);
@@ -121,6 +124,15 @@ thrcnt_inc(ref)
            croak("thrcnt can only be used on shared values");
        Perl_sharedsv_thrcnt_inc(aTHX_ shared);
 
+void
+_thrcnt_dec(ref)
+        SV* ref
+        CODE:
+       shared_sv* shared = (shared_sv*) SvIV(ref);
+        if(!shared)
+           croak("thrcnt can only be used on shared values");
+       Perl_sharedsv_thrcnt_dec(aTHX_ shared);
+
 
 MODULE = threads::shared               PACKAGE = threads::shared::sv