]> git.ipfire.org Git - thirdparty/ccache.git/commitdiff
feat: Use subsecond timestamps for include file check
authorJoel Rosdahl <joel@rosdahl.net>
Tue, 20 Sep 2022 17:05:38 +0000 (19:05 +0200)
committerJoel Rosdahl <joel@rosdahl.net>
Wed, 21 Sep 2022 15:06:33 +0000 (17:06 +0200)
To avoid a race condition, ccache disables the direct mode if an include
file has a too new mtime or ctime. Previously this check used one second
resolution timestamps, which meant that a generated include file often
would disable direct mode hits for up to one second. Now ccache uses
timestamps with subsecond resolution (nanoseconds on Linux), so the
direct mode will in practice no longer have to be disabled for generated
include files.

doc/MANUAL.adoc
src/ccache.cpp

index 290d3cf30e311da0e405af99b4c2ed5b4180c130..8011e0d9f95f96505ee26166da82c9bf47d73948 100644 (file)
@@ -962,13 +962,13 @@ Examples:
     directory in the `.gcno` file. *gcno_cwd* also disables hashing of the
     current working directory if `-fprofile-abs-path` is used.
 *include_file_ctime*::
-    By default, ccache will not cache a file if it includes a header whose ctime
-    is too new. This sloppiness disables that check. See also
-    _<<Handling of newly created header files>>_.
+    By default, ccache will disable the direct mode if an include file has too
+    new ctime. This sloppiness disables that check. See also _<<Handling of
+    newly created header files>>_.
 *include_file_mtime*::
-    By default, ccache will not cache a file if it includes a header whose mtime
-    is too new. This sloppiness disables that check. See also
-    _<<Handling of newly created header files>>_.
+    By default, ccache will disable the direct mode if an include file has too
+    new mtime. This sloppiness disables that check. See also _<<Handling of
+    newly created header files>>_.
 *ivfsoverlay*::
     Ignore the Clang compiler option `-ivfsoverlay` and its argument. This is
     useful if you use Xcode, which uses a virtual file system (VFS) for things
index 94d4a561aafe9cf3b583447eef6b18327fffa1ed..c127c6d22da26881afa818d47c6b8afaada697e1 100644 (file)
@@ -262,14 +262,14 @@ include_file_too_new(const Context& ctx,
   // starting compilation and writing the include file. See also the notes under
   // "Performance" in doc/MANUAL.adoc.
   if (!(ctx.config.sloppiness().is_enabled(core::Sloppy::include_file_mtime))
-      && path_stat.mtime().sec() >= ctx.time_of_compilation.sec()) {
+      && path_stat.mtime() >= ctx.time_of_compilation) {
     LOG("Include file {} too new", path);
     return true;
   }
 
   // The same >= logic as above applies to the change time of the file.
   if (!(ctx.config.sloppiness().is_enabled(core::Sloppy::include_file_ctime))
-      && path_stat.ctime().sec() >= ctx.time_of_compilation.sec()) {
+      && path_stat.ctime() >= ctx.time_of_compilation) {
     LOG("Include file {} ctime too new", path);
     return true;
   }
@@ -774,10 +774,6 @@ update_manifest(Context& ctx,
 
   MTR_SCOPE("manifest", "manifest_put");
 
-  // {m,c}time() have a resolution of 1 second, so we can cache the file's mtime
-  // and ctime only if they're at least one second older than
-  // time_of_compilation.
-  //
   // ctime() may be 0, so we have to check time_of_compilation against
   // MAX(mtime, ctime).
   //