2008-10-26 Ralf Wildenhues <Ralf.Wildenhues@gmx.de>
+ 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),
-# 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
# 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<Location> objects are used to keep track of locations in Automake,
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<Automake::Channels>