Merge change 23474 into eclair

* changes:
  Breaking sleep after yield into small quanta.
This commit is contained in:
Android (Google) Code Review
2009-09-01 13:03:58 -07:00

View File

@@ -189,6 +189,8 @@ public class SQLiteDatabase extends SQLiteClosable {
private static final int LOCK_ACQUIRED_WARNING_THREAD_TIME_IN_MS = 100; private static final int LOCK_ACQUIRED_WARNING_THREAD_TIME_IN_MS = 100;
private static final int LOCK_ACQUIRED_WARNING_TIME_IN_MS_ALWAYS_PRINT = 2000; private static final int LOCK_ACQUIRED_WARNING_TIME_IN_MS_ALWAYS_PRINT = 2000;
private static final int SLEEP_AFTER_YIELD_QUANTUM = 500;
private long mLastLockMessageTime = 0L; private long mLastLockMessageTime = 0L;
/** Used by native code, do not rename */ /** Used by native code, do not rename */
@@ -567,10 +569,21 @@ public class SQLiteDatabase extends SQLiteClosable {
} }
} }
if (sleepAfterYieldDelay > 0) { if (sleepAfterYieldDelay > 0) {
try { // Sleep for up to sleepAfterYieldDelay milliseconds, waking up periodically to
Thread.sleep(sleepAfterYieldDelay); // check if anyone is using the database. If the database is not contended,
} catch (InterruptedException e) { // retake the lock and return.
Thread.interrupted(); long remainingDelay = sleepAfterYieldDelay;
while (remainingDelay > 0) {
try {
Thread.sleep(remainingDelay < SLEEP_AFTER_YIELD_QUANTUM ?
remainingDelay : SLEEP_AFTER_YIELD_QUANTUM);
} catch (InterruptedException e) {
Thread.interrupted();
}
remainingDelay -= SLEEP_AFTER_YIELD_QUANTUM;
if (mLock.getQueueLength() == 0) {
break;
}
} }
} }
beginTransaction(); beginTransaction();