From 5c7aede8d69f4f0ad617d39decd4453b029ba6af Mon Sep 17 00:00:00 2001 From: Fred Quintana Date: Thu, 27 Aug 2009 21:41:27 -0700 Subject: allow delaying after yielding --- api/current.xml | 13 +++++++++ .../android/database/sqlite/SQLiteDatabase.java | 31 +++++++++++++++++++--- 2 files changed, 40 insertions(+), 4 deletions(-) diff --git a/api/current.xml b/api/current.xml index e75f2b28f13b..96e1d2d93382 100644 --- a/api/current.xml +++ b/api/current.xml @@ -47785,6 +47785,19 @@ visibility="public" > + + + + 0, sleep this long before starting a new transaction if + * the lock was actually yielded. This will allow other background threads to make some + * more progress than they would if we started the transaction immediately. + * @return true if the transaction was yielded + */ + public boolean yieldIfContendedSafely(long sleepAfterYieldDelay) { + return yieldIfContendedHelper(true /* check yielding */, sleepAfterYieldDelay); + } + + private boolean yieldIfContendedHelper(boolean checkFullyYielded, long sleepAfterYieldDelay) { if (mLock.getQueueLength() == 0) { // Reset the lock acquire time since we know that the thread was willing to yield // the lock at this time. @@ -550,6 +566,13 @@ public class SQLiteDatabase extends SQLiteClosable { "Db locked more than once. yielfIfContended cannot yield"); } } + if (sleepAfterYieldDelay > 0) { + try { + Thread.sleep(sleepAfterYieldDelay); + } catch (InterruptedException e) { + Thread.interrupted(); + } + } beginTransaction(); return true; } -- cgit v1.2.3-59-g8ed1b