autoconf-patches
[Top][All Lists]
Advanced

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

FYI: Locking autom4te.cache


From: Akim Demaille
Subject: FYI: Locking autom4te.cache
Date: Tue, 06 May 2003 09:34:34 +0200
User-agent: Gnus/5.1001 (Gnus v5.10.1) Emacs/21.3 (gnu/linux)

I fail to see how to exercise this, but at least running
simultaneously autoheader, autoconf and automake on Bison resulted in
the correct result.

Index: ChangeLog
from  Akim Demaille  <address@hidden>

        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.

Index: NEWS
===================================================================
RCS file: /cvsroot/autoconf/autoconf/NEWS,v
retrieving revision 1.291
diff -u -u -r1.291 NEWS
--- NEWS 12 Apr 2003 20:53:19 -0000 1.291
+++ NEWS 6 May 2003 07:34:03 -0000
@@ -14,6 +14,11 @@
     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: bin/autom4te.in
===================================================================
RCS file: /cvsroot/autoconf/autoconf/bin/autom4te.in,v
retrieving revision 1.80
diff -u -u -r1.80 autom4te.in
--- bin/autom4te.in 28 Feb 2003 10:11:11 -0000 1.80
+++ bin/autom4te.in 6 May 2003 07:34:08 -0000
@@ -6,7 +6,7 @@
     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 @@
 }
 
 
-# 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 @@
 
 # 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: address@hidden" 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: address@hidden" if $@;
 }
 
 
@@ -251,11 +255,12 @@
 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 @@
 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 @@
       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 @@
 $req->valid (1)
   if $exit_status == 0;
 
-Request->save ($icache);
+Request->save ($icache_file);
 
 exit $exit_status;
 
Index: lib/Autom4te/XFile.pm
===================================================================
RCS file: /cvsroot/autoconf/autoconf/lib/Autom4te/XFile.pm,v
retrieving revision 1.5
diff -u -u -r1.5 XFile.pm
--- lib/Autom4te/XFile.pm 2 Jul 2002 20:31:22 -0000 1.5
+++ lib/Autom4te/XFile.pm 6 May 2003 07:34:09 -0000
@@ -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 @@
 
 =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 @@
 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 @@
 
 @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 @@
 
   if (!$fh->SUPER::open (@_))
     {
-      my $me = basename ($0);
       croak "$me: cannot open $file: $!\n";
     }
 
@@ -158,8 +162,7 @@
   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 @@
 # 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 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: man/autom4te.1
===================================================================
RCS file: /cvsroot/autoconf/autoconf/man/autom4te.1,v
retrieving revision 1.53
diff -u -u -r1.53 autom4te.1
--- man/autom4te.1 6 May 2003 07:04:42 -0000 1.53
+++ man/autom4te.1 6 May 2003 07:34:09 -0000
@@ -111,12 +111,13 @@
 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 <address@hidden>.
+.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),




reply via email to

[Prev in Thread] Current Thread [Next in Thread]