summaryrefslogtreecommitdiff
path: root/lib/Automake/DisjConditions.pm
diff options
context:
space:
mode:
authorRalf Wildenhues <Ralf.Wildenhues@gmx.de>2008-10-19 19:54:12 +0200
committerRalf Wildenhues <Ralf.Wildenhues@gmx.de>2008-10-19 19:54:12 +0200
commitc15d9a8e130cd79e9d79a8ede5a8f431ead5216f (patch)
tree8c74484dccbd19193c5f7a146d9f723294b0ee86 /lib/Automake/DisjConditions.pm
parentb6af214094ead458695113c17d7a2cade7c54dbc (diff)
downloadautomake-c15d9a8e130cd79e9d79a8ede5a8f431ead5216f.tar.gz
Fix DisjConditions module to be thread-safe for perl >= 5.7.2.
Self-hashes of blessed references are not correctly transported through thread creation. This patch fixes that by recreating the hashes upon thread creation with a CLONE special subroutine, which is automatically invoked by new enough Perl versions. * lib/Automake/DisjConditions.pm (CLONE): New special subroutine to fix self hashes upon thread creation. * lib/Automake/tests/Condition-t.pl: New, sister test to Condition.pl, but spawns a new threads after each creation of a new condition; skip test if perl is too old or ithreads are not available. * lib/Automake/tests/DisjConditions-t.pl: Likewise. * lib/Automake/tests/Makefile.am (TESTS): Add them. Signed-off-by: Ralf Wildenhues <Ralf.Wildenhues@gmx.de>
Diffstat (limited to 'lib/Automake/DisjConditions.pm')
-rw-r--r--lib/Automake/DisjConditions.pm20
1 files changed, 20 insertions, 0 deletions
diff --git a/lib/Automake/DisjConditions.pm b/lib/Automake/DisjConditions.pm
index 1f09c0fd4..ae759e27c 100644
--- a/lib/Automake/DisjConditions.pm
+++ b/lib/Automake/DisjConditions.pm
@@ -192,6 +192,26 @@ sub new ($;@)
return $self;
}
+
+=item C<CLONE>
+
+Internal special subroutine to fix up the self hashes in
+C<%_disjcondition_singletons> upon thread creation. C<CLONE> is invoked
+automatically with ithreads from Perl 5.7.2 or later, so if you use this
+module with earlier versions of Perl, it is not thread-safe.
+
+=cut
+
+sub CLONE
+{
+ foreach my $self (values %_disjcondition_singletons)
+ {
+ my %h = map { $_ => $_ } @{$self->{'conds'}};
+ $self->{'hash'} = \%h;
+ }
+}
+
+
=item C<@conds = $set-E<gt>conds>
Return the list of C<Condition> objects involved in C<$set>.