mirror of
https://github.com/NixOS/nix
synced 2025-07-04 19:41:48 +02:00
Make SQLite busy back-off logic portable
Use C++ standard library not Unix functions for sleeping and randomness. Suggested by @edolstra in https://github.com/NixOS/nix/pull/8901#discussion_r1550416615
This commit is contained in:
parent
12ec3154b8
commit
1577b5fa67
1 changed files with 3 additions and 4 deletions
|
@ -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);
|
|
||||||
}
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue