Merge pull request #10399 from nix-windows/portable-sleep

Make SQLite busy back-off logic portable
This commit is contained in:
John Ericson 2024-04-04 13:08:42 -04:00 committed by GitHub
commit 6b889e0588
No known key found for this signature in database
GPG key ID: B5690EEEBB952194

View file

@ -7,6 +7,7 @@
#include <sqlite3.h> #include <sqlite3.h>
#include <atomic> #include <atomic>
#include <thread>
namespace nix { namespace nix {
@ -256,10 +257,8 @@ void handleSQLiteBusy(const SQLiteBusy & e, time_t & nextWarning)
/* Sleep for a while since retrying the transaction right away /* Sleep for a while since retrying the transaction right away
is likely to fail again. */ is likely to fail again. */
checkInterrupt(); checkInterrupt();
struct timespec t; /* <= 0.1s */
t.tv_sec = 0; std::this_thread::sleep_for(std::chrono::milliseconds { rand() % 100 });
t.tv_nsec = (random() % 100) * 1000 * 1000; /* <= 0.1s */
nanosleep(&t, 0);
} }
} }