]> git.ipfire.org Git - thirdparty/ccache.git/commitdiff
Cap time to sleep to 10 ms when failing to acquire a lock
authorJoel Rosdahl <joel@rosdahl.net>
Wed, 26 Feb 2020 21:48:31 +0000 (22:48 +0100)
committerJoel Rosdahl <joel@rosdahl.net>
Tue, 3 Mar 2020 19:21:49 +0000 (20:21 +0100)
(cherry picked from commit 41ffc7ec009237da51040c6059b1bcd7903af30d)

src/lockfile.cpp

index a58a4907b136a369d209a186f92e38177d5586f8..6905b3e3a59331804412d4f8985178507bfab7fa 100644 (file)
@@ -38,8 +38,9 @@ lockfile_acquire(const char* path, unsigned staleness_limit)
   char* initial_content = nullptr;
   const char* hostname = get_hostname();
   bool acquired = false;
-  unsigned to_sleep = 1000; // Microseconds.
-  unsigned slept = 0;       // Microseconds.
+  unsigned to_sleep = 1000;      // Microseconds.
+  unsigned max_to_sleep = 10000; // Microseconds.
+  unsigned slept = 0;            // Microseconds.
 
   while (true) {
     free(my_content);
@@ -171,7 +172,7 @@ lockfile_acquire(const char* path, unsigned staleness_limit)
            to_sleep);
     usleep(to_sleep);
     slept += to_sleep;
-    to_sleep *= 2;
+    to_sleep = std::min(max_to_sleep, 2 * to_sleep);
   }
 
 out: