]> git.ipfire.org Git - thirdparty/autoconf.git/commitdiff
Lock autom4te's cache.
authorAkim Demaille <akim@epita.fr>
Tue, 6 May 2003 08:51:21 +0000 (08:51 +0000)
committerAkim Demaille <akim@epita.fr>
Tue, 6 May 2003 08:51:21 +0000 (08:51 +0000)
* lib/Autom4te/XFile.pm ($me, &name, &lock, &truncate, &seek): New.
* bin/autom4te.in (&Request::save, &Request::load): Use an IO::File
argument instead of a file name, so that the request file remains
open during the whole autom4te run.
($icache_file): New.
(&freeze): Lock the $icache_file.

ChangeLog
NEWS
bin/autom4te.in
lib/Autom4te/XFile.pm
man/autom4te.1

index e89c2bcba66e7091dc2dd6d106bb4f7820f0cec3..8892003e543dd24e11872eece30b23e48a5b6c7b 100644 (file)
--- a/ChangeLog
+++ b/ChangeLog
@@ -1,6 +1,13 @@
-2003-05-05  Derek Price  <derek@ximbiot.com>
+2003-05-06  Akim Demaille  <akim@epita.fr>
 
-       * lib/emacs/.cvsignore: Add generated elc-stamp file.
+       Lock autom4te's cache.
+
+       * lib/Autom4te/XFile.pm ($me, &name, &lock, &truncate, &seek): New.
+       * bin/autom4te.in (&Request::save, &Request::load): Use an IO::File
+       argument instead of a file name, so that the request file remains
+       open during the whole autom4te run.
+       ($icache_file): New.
+       (&freeze): Lock the $icache_file.
 
 2003-04-29  Derek Price  <derek@ximbiot.com>
 
diff --git a/NEWS b/NEWS
index 1e98c026ff995860b6a3cffc3628621f491afea0..7a65da06129059c3a5f8168c2015956112befd60 100644 (file)
--- a/NEWS
+++ b/NEWS
     configure: WARNING: pi.h: proceeding with the preprocessor's result
       messages.
 
+* Concurrent executions of autom4te
+  autom4te now locks its internal files, which enables concurrent
+  executions of autom4te, likely to happen if automake, autoconf,
+  autoheader etc. are run simultaneously.
+
 * Major changes in Autoconf 2.57
 
   Released 2002-12-03 by Paul Eggert.
index b2d3995285666906c996503bbc40a78d274c0ef0..238f81e7d3f2b8361028656007259f8aa1e93c31 100644 (file)
@@ -6,7 +6,7 @@ eval 'case $# in 0) exec @PERL@ -S "$0";; *) exec @PERL@ -S "$0" "$@";; esac'
     if 0;
 
 # autom4te - Wrapper around M4 libraries.
-# Copyright (C) 2001, 2002 Free Software Foundation, Inc.
+# Copyright (C) 2001, 2002, 2003 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
@@ -189,17 +189,19 @@ sub includes_p
 }
 
 
-# SAVE ($FILENAME)
-# ----------------
+# SAVE ($FILE)
+# ------------
+# Save the cache in the $FILE Autom4te::XFile object.
 sub save
 {
-  my ($self, $filename) = @_;
+  my ($self, $file) = @_;
 
   croak "$me: cannot save a single request\n"
     if ref ($self);
 
-  my $requests = new Autom4te::XFile ("> $filename");
-  print $requests
+  $file->seek (0, 0);
+  $file->truncate (0);
+  print $file
     "# This file was created by $me.\n",
     "# It contains the lists of macros which have been traced.\n",
     "# It can be safely removed.\n",
@@ -210,18 +212,20 @@ sub save
 
 # LOAD ($FILE)
 # ------------
+# "eval" the content of the $FILE Autom4te::XFile object.
 sub load
 {
   my ($self, $file) = @_;
+  my $fname = $file->name;
 
   croak "$me: cannot load a single request\n"
     if ref ($self);
 
-  (my $return) = do "$file";
+  my $contents = join "", $file->getlines;
 
-  croak "$me: cannot parse $file: $@\n" if $@;
-  croak "$me: cannot do $file: $!\n"    unless defined $return;
-  croak "$me: cannot run $file\n"       unless $return;
+  eval $contents;
+
+  croak "$me: cannot eval $fname: $@\n" if $@;
 }
 
 
@@ -251,11 +255,12 @@ my $mode = "0666";
 my $melt = 0;
 
 # Names of the cache directory, cache directory index, trace cache
-# prefix, and output cache prefix.
+# prefix, and output cache prefix.  And the IO objet for the index.
 my $cache;
 my $icache;
 my $tcache;
 my $ocache;
+my $icache_file;
 
 # The macros to trace mapped to their format, as specified by the
 # user.
@@ -415,7 +420,7 @@ $version =  <<"EOF";
 autom4te (@PACKAGE_NAME@) @VERSION@
 Written by Akim Demaille.
 
-Copyright 2002 Free Software Foundation, Inc.
+Copyright (C) 2003 Free Software Foundation, Inc.
 This is free software; see the source for copying conditions.  There is NO
 warranty; not even for MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.
 EOF
@@ -1170,10 +1175,16 @@ if (! -d "$cache")
       or error "cannot create $cache: $!";
   }
 
+# Open the index for update, and lock it.  autom4te handles several
+# files, but the index is the first and last file to be update, so
+# locking it is sufficient.
+$icache_file = new Autom4te::XFile $icache, O_RDWR|O_CREAT;
+$icache_file->lock (LOCK_EX);
+
 # Read the cache index if available and older than autom4te itself.
 # If autom4te is younger, then some structures such as Request, might
 # have changed, which would corrupt its processing.
-Request->load ($icache)
+Request->load ($icache_file)
   if -f $icache && mtime ($icache) > mtime ($0);
 
 # Add the new trace requests.
@@ -1216,7 +1227,7 @@ else
 $req->valid (1)
   if $exit_status == 0;
 
-Request->save ($icache);
+Request->save ($icache_file);
 
 exit $exit_status;
 
index 477537f2d411ccd00a3a420681cc2113e46ac558..abc75e5bb49fa2530bc60bfc94ed287c98c144d6 100644 (file)
@@ -1,4 +1,4 @@
-# Copyright 2001 Free Software Foundation, Inc.
+# Copyright (C) 2001, 2003 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
@@ -63,9 +63,11 @@ Autom4te::XFile - supply object methods for filehandles with error handling
 
 =head1 DESCRIPTION
 
-C<Autom4te::XFile> inherits from C<IO::File>.  It provides dying
-version of the methods C<open>, C<new>, and C<close>.  It also overrides
-the C<getline> and C<getlines> methods to translate C<\r\n> to C<\n>.
+C<Autom4te::XFile> inherits from C<IO::File>.  It provides the method
+C<name> returning the file name.  It provides dying version of the
+methods C<close>, C<lock> (corresponding to C<flock>), C<new>,
+C<open>, C<seek>, and C<trunctate>.  It also overrides the C<getline>
+and C<getlines> methods to translate C<\r\n> to C<\n>.
 
 =head1 SEE ALSO
 
@@ -85,6 +87,7 @@ require 5.000;
 use strict;
 use vars qw($VERSION @EXPORT @EXPORT_OK $AUTOLOAD @ISA);
 use Carp;
+use IO::File;
 use File::Basename;
 
 require Exporter;
@@ -92,18 +95,20 @@ require DynaLoader;
 
 @ISA = qw(IO::File Exporter DynaLoader);
 
-$VERSION = "1.1";
+$VERSION = "1.2";
 
 @EXPORT = @IO::File::EXPORT;
 
 eval {
-    # Make all Fcntl O_XXX constants available for importing
-    require Fcntl;
-    my @O = grep /^O_/, @Fcntl::EXPORT;
-    Fcntl->import(@O);  # first we import what we want to export
-    push(@EXPORT, @O);
+  # Make all Fcntl O_XXX and LOCK_XXX constants available for importing
+  require Fcntl;
+  my @O = grep /^(LOCK|O)_/, @Fcntl::EXPORT, @Fcntl::EXPORT_OK;
+  Fcntl->import (@O);  # first we import what we want to export
+  push (@EXPORT, @O);
 };
 
+# Used in croak error messages.
+my $me = basename ($0);
 
 ################################################
 ## Constructor
@@ -138,7 +143,6 @@ sub open
 
   if (!$fh->SUPER::open (@_))
     {
-      my $me = basename ($0);
       croak "$me: cannot open $file: $!\n";
     }
 
@@ -158,8 +162,7 @@ sub close
   my ($fh) = shift;
   if (!$fh->SUPER::close (@_))
     {
-      my $me = basename ($0);
-      my $file = ${*$fh}{'autom4te_xfile_file'};
+      my $file = $fh->name;
       croak "$me: cannot close $file: $!\n";
     }
 }
@@ -172,11 +175,11 @@ sub close
 # so we do that here.
 sub getline
 {
-    local $_ = $_[0]->SUPER::getline;
-    # Perform a _global_ replacement: $_ may can contains many lines
-    # in slurp mode ($/ = undef).
-    s/\015\012/\n/gs if defined $_;
-    return $_;
+  local $_ = $_[0]->SUPER::getline;
+  # Perform a _global_ replacement: $_ may can contains many lines
+  # in slurp mode ($/ = undef).
+  s/\015\012/\n/gs if defined $_;
+  return $_;
 }
 
 ################################################
@@ -185,10 +188,64 @@ sub getline
 
 sub getlines
 {
-    my @res = ();
-    my $line;
-    push @res, $line while $line = $_[0]->getline;
-    return @res;
+  my @res = ();
+  my $line;
+  push @res, $line while $line = $_[0]->getline;
+  return @res;
+}
+
+################################################
+## Name
+##
+
+sub name
+{
+  my ($fh) = shift;
+  return ${*$fh}{'autom4te_xfile_file'};
+}
+
+################################################
+## Lock
+##
+
+sub lock
+{
+  use Fcntl qw(:DEFAULT :flock);
+  my ($fh) = shift;
+  if (!flock ($fh, @_))
+    {
+      my $file = $fh->name;
+      croak "$me: cannot lock $file with @_: $!\n";
+    }
+}
+
+################################################
+## Seek
+##
+
+sub seek
+{
+  my ($fh) = shift;
+  # Cannot use @_ here.
+  if (!seek ($fh, $_[0], $_[1]))
+    {
+      my $file = $fh->name;
+      croak "$me: cannot rewind $file with @_: $!\n";
+    }
+}
+
+################################################
+## Truncate
+##
+
+sub truncate
+{
+  my ($fh) = shift;
+  if (!truncate ($fh, @_))
+    {
+      my $file = $fh->name;
+      croak "$me: cannot truncate $file with @_: $!\n";
+    }
 }
 
 1;
index 2714d21252e7a7a800eef1773945198e96e53817..dd1e48aaf70b4395a2e18143d373fa8770c78e5a 100644 (file)
@@ -111,12 +111,13 @@ prepare to trace MACRO in a future run
 produce an M4 frozen state file for FILES
 .SH AUTHOR
 Written by Akim Demaille.
-.PP
-Copyright 2002 Free Software Foundation, Inc.
-This is free software; see the source for copying conditions.  There is NO
-warranty; not even for MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.
 .SH "REPORTING BUGS"
 Report bugs to <bug-autoconf@gnu.org>.
+.SH COPYRIGHT
+Copyright \(co 2003 Free Software Foundation, Inc.
+.br
+This is free software; see the source for copying conditions.  There is NO
+warranty; not even for MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.
 .SH "SEE ALSO"
 .BR autoconf (1),
 .BR automake (1),