summaryrefslogtreecommitdiff
path: root/ext/threads
diff options
context:
space:
mode:
authorArtur Bergman <sky@nanisky.com>2001-10-26 11:35:47 +0000
committerArtur Bergman <sky@nanisky.com>2001-10-26 11:35:47 +0000
commit938785a29d4f7c59a64a93320a37f15bb52259b4 (patch)
treee1c204e5b005ceb89933140c26deb0c2dcc81b98 /ext/threads
parent409b1fd3668e7a4d9e663c5b16ba2364947b127b (diff)
downloadperl-938785a29d4f7c59a64a93320a37f15bb52259b4.tar.gz
Extend support of change #12672 to support arrays and hashes. Shared reference support is
complete bar support for blessed objects. TODO: tests for shared arrays and more hv reference tests. Also a complex test testing all types intermixed. p4raw-link: @12672 on //depot/perl: 409b1fd3668e7a4d9e663c5b16ba2364947b127b p4raw-id: //depot/perl@12673
Diffstat (limited to 'ext/threads')
-rw-r--r--ext/threads/shared/shared.xs28
-rw-r--r--ext/threads/shared/t/hv_refs.t15
2 files changed, 41 insertions, 2 deletions
diff --git a/ext/threads/shared/shared.xs b/ext/threads/shared/shared.xs
index ed5ddfd7b3..b297098bff 100644
--- a/ext/threads/shared/shared.xs
+++ b/ext/threads/shared/shared.xs
@@ -21,6 +21,34 @@ SV* shared_sv_attach_sv (SV* sv, shared_sv* shared) {
}
} else {
switch(SvTYPE(SHAREDSvGET(shared))) {
+ case SVt_PVAV: {
+ SV* weakref;
+ SV* obj_ref = newSViv(0);
+ SV* obj = newSVrv(obj_ref,"threads::shared::av");
+ AV* hv = newAV();
+ sv_setiv(obj,(IV)shared);
+ weakref = newRV((SV*)hv);
+ sv = newRV_noinc((SV*)hv);
+ sv_rvweaken(weakref);
+ sv_magic((SV*) hv, obj_ref, PERL_MAGIC_tied, Nullch, 0);
+ hv_store(shared_hv, SvPV(id,length), length, weakref, 0);
+ Perl_sharedsv_thrcnt_inc(aTHX_ shared);
+ }
+ break;
+ case SVt_PVHV: {
+ SV* weakref;
+ SV* obj_ref = newSViv(0);
+ SV* obj = newSVrv(obj_ref,"threads::shared::hv");
+ HV* hv = newHV();
+ sv_setiv(obj,(IV)shared);
+ weakref = newRV((SV*)hv);
+ sv = newRV_noinc((SV*)hv);
+ sv_rvweaken(weakref);
+ sv_magic((SV*) hv, obj_ref, PERL_MAGIC_tied, Nullch, 0);
+ hv_store(shared_hv, SvPV(id,length), length, weakref, 0);
+ Perl_sharedsv_thrcnt_inc(aTHX_ shared);
+ }
+ break;
default: {
MAGIC* shared_magic;
SV* value = newSVsv(SHAREDSvGET(shared));
diff --git a/ext/threads/shared/t/hv_refs.t b/ext/threads/shared/t/hv_refs.t
index 5181dbd76e..c10b36d860 100644
--- a/ext/threads/shared/t/hv_refs.t
+++ b/ext/threads/shared/t/hv_refs.t
@@ -24,7 +24,7 @@ sub ok {
use ExtUtils::testlib;
use strict;
-BEGIN { print "1..7\n" };
+BEGIN { print "1..17\n" };
use threads;
use threads::shared;
ok(1,1,"loaded");
@@ -58,5 +58,16 @@ ok(11, threads::shared::_thrcnt($gg) == 1, "Check refcount");
ok(12, $gg == $gg2, "Check we get the same reference ($gg == $gg2)");
ok(13, $$gg eq $$gg2, "And check the values are the same");
ok(14, keys %foo == 0, "And make sure we realy have deleted the values");
-
+{
+ my (%hash1, %hash2);
+ share(%hash1);
+ share(%hash2);
+ $hash1{hash} = \%hash2;
+ $hash2{"bar"} = "foo";
+ ok(15, $hash1{hash}->{bar} eq "foo", "Check hash references work");
+ threads->create(sub { $hash2{"bar2"} = "foo2"})->join();
+ ok(16, $hash1{hash}->{bar2} eq "foo2", "Check hash references work");
+ threads->create(sub { my (%hash3); share(%hash3); $hash2{hash} = \%hash3; $hash3{"thread"} = "yes"})->join();
+ ok(17, $hash1{hash}->{hash}->{thread} eq "yes", "Check hash created in another thread");
+}