diff --git a/sql/sqlite_features_unittest.cc b/sql/sqlite_features_unittest.cc index 1aff80e9bbac2..987d3a1f5d193 100644 --- a/sql/sqlite_features_unittest.cc +++ b/sql/sqlite_features_unittest.cc @@ -112,4 +112,21 @@ TEST_F(SQLiteFeaturesTest, FTS3_Prefix) { } #endif +#if !defined(USE_SYSTEM_SQLITE) +// Verify that Chromium's SQLite is compiled with HAVE_USLEEP defined. With +// HAVE_USLEEP, SQLite uses usleep() with millisecond granularity. Otherwise it +// uses sleep() with second granularity. +TEST_F(SQLiteFeaturesTest, UsesUsleep) { + base::TimeTicks before = base::TimeTicks::Now(); + sqlite3_sleep(1); + base::TimeDelta delta = base::TimeTicks::Now() - before; + + // It is not impossible for this to be over 1000 if things are compiled the + // right way. But it is very unlikely, most platforms seem to be around + // <TBD>. + LOG(ERROR) << "Milliseconds: " << delta.InMilliseconds(); + EXPECT_LT(delta.InMilliseconds(), 1000); +} +#endif + } // namespace diff --git a/third_party/sqlite/BUILD.gn b/third_party/sqlite/BUILD.gn index 3d994d2053d70..f4c9a44912fdd 100644 --- a/third_party/sqlite/BUILD.gn +++ b/third_party/sqlite/BUILD.gn @@ -45,6 +45,15 @@ source_set("sqlite") { "SQLITE_NO_SYNC", ] } + if (is_posix) { + defines += [ + # Allow xSleep() call on Unix to use usleep() rather than sleep(), so it + # will have microsecond precision. Should only affect contended databases + # via the busy callback. Browser profile databases are mostly exclusive, + # but renderer databases may allow for contention. + "HAVE_USLEEP=1", + ] + } include_dirs = [ "amalgamation", @@ -69,7 +78,6 @@ source_set("sqlite") { libs = [ "CoreFoundation.framework" ] } else if (is_android) { defines += [ - "HAVE_USLEEP=1", "SQLITE_DEFAULT_JOURNAL_SIZE_LIMIT=1048576", "SQLITE_DEFAULT_AUTOVACUUM=1", "SQLITE_TEMP_STORE=3", diff --git a/third_party/sqlite/sqlite.gyp b/third_party/sqlite/sqlite.gyp index 3e55b1103cd77..bb18457a34cce 100644 --- a/third_party/sqlite/sqlite.gyp +++ b/third_party/sqlite/sqlite.gyp @@ -33,6 +33,16 @@ ], }, ], + ['os_posix == 1', { + 'defines': [ + # Allow xSleep() call on Unix to use usleep() rather than sleep(). + # Microsecond precision is better than second precision. Should + # only affect contended databases via the busy callback. Browser + # profile databases are mostly exclusive, but renderer databases may + # allow for contention. + 'HAVE_USLEEP=1', + ], + }], ['use_system_sqlite', { 'type': 'none', 'direct_dependent_settings': { @@ -132,7 +142,6 @@ }], ['OS == "android"', { 'defines': [ - 'HAVE_USLEEP=1', 'SQLITE_DEFAULT_JOURNAL_SIZE_LIMIT=1048576', 'SQLITE_DEFAULT_AUTOVACUUM=1', 'SQLITE_TEMP_STORE=3',