From: Joel Rosdahl Date: Wed, 26 Feb 2020 21:48:31 +0000 (+0100) Subject: Cap time to sleep to 10 ms when failing to acquire a lock X-Git-Tag: v3.7.8~5 X-Git-Url: http://git.ipfire.org/gitweb/gitweb.cgi?a=commitdiff_plain;h=41ffc7ec009237da51040c6059b1bcd7903af30d;p=thirdparty%2Fccache.git Cap time to sleep to 10 ms when failing to acquire a lock --- diff --git a/src/lockfile.c b/src/lockfile.c index 9d1a49db2..0bdb87739 100644 --- a/src/lockfile.c +++ b/src/lockfile.c @@ -1,4 +1,4 @@ -// Copyright (C) 2010-2018 Joel Rosdahl +// Copyright (C) 2010-2020 Joel Rosdahl // // 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 the Free @@ -34,6 +34,7 @@ lockfile_acquire(const char *path, unsigned staleness_limit) const char *hostname = get_hostname(); bool acquired = false; unsigned to_sleep = 1000; // Microseconds. + unsigned max_to_sleep = 10000; // Microseconds. unsigned slept = 0; // Microseconds. while (true) { @@ -164,7 +165,7 @@ lockfile_acquire(const char *path, unsigned staleness_limit) lockfile, to_sleep); usleep(to_sleep); slept += to_sleep; - to_sleep *= 2; + to_sleep = MIN(max_to_sleep, 2 * to_sleep); } out: