From: Ralf Wildenhues Date: Sun, 26 Oct 2008 19:38:06 +0000 (+0100) Subject: Implement serialization for Locations. X-Git-Tag: v1.10b~74 X-Git-Url: http://git.ipfire.org/cgi-bin/gitweb.cgi?a=commitdiff_plain;h=be6de492fc71c2249e6d080a3e5050a4e0ad4334;p=thirdparty%2Fautomake.git Implement serialization for Locations. * lib/Automake/Location.pm (serialize, deserialize): New functions. They allows to serialize a Location in an array, and to restore a Location from a thread queue. The API is unsymmetric (array vs. queue) because enqueuing data needs to happen atomically. Signed-off-by: Ralf Wildenhues --- diff --git a/ChangeLog b/ChangeLog index de78a03f1..10b0b5fdc 100644 --- a/ChangeLog +++ b/ChangeLog @@ -1,5 +1,12 @@ 2008-10-26 Ralf Wildenhues + Implement serialization for Locations. + * lib/Automake/Location.pm (serialize, deserialize): New + functions. They allows to serialize a Location in an array, and + to restore a Location from a thread queue. The API is + unsymmetric (array vs. queue) because enqueuing data needs to + happen atomically. + Parallel automake: ordered output messages. * lib/Automake/Channels.pm (%_default_options): New options `ordered' default enabled, `queue', default zero (no queue), diff --git a/lib/Automake/Location.pm b/lib/Automake/Location.pm index 33f526a57..90534f19c 100644 --- a/lib/Automake/Location.pm +++ b/lib/Automake/Location.pm @@ -1,4 +1,4 @@ -# Copyright (C) 2002, 2003 Free Software Foundation, Inc. +# Copyright (C) 2002, 2003, 2008 Free Software Foundation, Inc. # This program is free software; you can redistribute it and/or modify # it under the terms of the GNU General Public License as published by @@ -57,6 +57,13 @@ Automake::Location - a class for location tracking, with a stack of contexts # that would otherwise be modified. my $where_copy = $where->clone; + # Serialize a Location object (for passing through a thread queue, + # for example) + my @array = $where->serialize (); + + # De-serialize: recreate a Location object from a queue. + my $where = new Automake::Location::deserialize ($queue); + =head1 DESCRIPTION C objects are used to keep track of locations in Automake, @@ -145,6 +152,33 @@ sub dump ($) return $res; } +sub serialize ($) +{ + my ($self) = @_; + my @serial = (); + push @serial, $self->get; + my @contexts = $self->get_contexts; + for my $pair (@contexts) + { + push @serial, @{$pair}; + } + push @serial, undef; + return @serial; +} + +sub deserialize ($) +{ + my ($queue) = @_; + my $position = $queue->dequeue (); + my $self = new Automake::Location $position; + while (my $position = $queue->dequeue ()) + { + my $context = $queue->dequeue (); + push @{$self->{'contexts'}}, [$position, $context]; + } + return $self; +} + =head1 SEE ALSO L