mirror of
https://github.com/darlinghq/fmdb.git
synced 2025-02-20 13:53:44 +00:00
Merge pull request #323 from layerhq/enhancement/jitter-in-busy-handler
Add jitter to SQLite Busy handler
This commit is contained in:
commit
3d0bbdd679
@ -231,7 +231,11 @@ static int FMDBDatabaseBusyHandler(void *f, int count) {
|
||||
NSTimeInterval delta = [NSDate timeIntervalSinceReferenceDate] - (self->_startBusyRetryTime);
|
||||
|
||||
if (delta < [self maxBusyRetryTimeInterval]) {
|
||||
sqlite3_sleep(50); // milliseconds
|
||||
int requestedSleepInMillseconds = arc4random_uniform(50) + 50;
|
||||
int actualSleepInMilliseconds = sqlite3_sleep(requestedSleepInMillseconds);
|
||||
if (actualSleepInMilliseconds != requestedSleepInMillseconds) {
|
||||
NSLog(@"WARNING: Requested sleep of %i milliseconds, but SQLite returned %i. Maybe SQLite wasn't built with HAVE_USLEEP=1?", requestedSleepInMillseconds, actualSleepInMilliseconds);
|
||||
}
|
||||
return 1;
|
||||
}
|
||||
|
||||
|
Loading…
x
Reference in New Issue
Block a user