diff options
Diffstat (limited to 'src/com/android/launcher2/LauncherModel.java')
-rw-r--r-- | src/com/android/launcher2/LauncherModel.java | 36 |
1 files changed, 34 insertions, 2 deletions
diff --git a/src/com/android/launcher2/LauncherModel.java b/src/com/android/launcher2/LauncherModel.java index 00770b28a..99ebd962e 100644 --- a/src/com/android/launcher2/LauncherModel.java +++ b/src/com/android/launcher2/LauncherModel.java @@ -82,6 +82,7 @@ public class LauncherModel extends BroadcastReceiver { private DeferredHandler mHandler = new DeferredHandler(); private LoaderTask mLoaderTask; private boolean mIsLoaderTaskRunning; + private volatile boolean mFlushingWorkerThread; // Specific runnable types that are run on the main thread deferred handler, this allows us to // clear all queued binding runnables when the Launcher activity is destroyed. @@ -375,6 +376,35 @@ public class LauncherModel extends BroadcastReceiver { runOnWorkerThread(r); } + public void flushWorkerThread() { + mFlushingWorkerThread = true; + Runnable waiter = new Runnable() { + public void run() { + synchronized (this) { + notifyAll(); + mFlushingWorkerThread = false; + } + } + }; + + synchronized(waiter) { + runOnWorkerThread(waiter); + if (mLoaderTask != null) { + synchronized(mLoaderTask) { + mLoaderTask.notify(); + } + } + boolean success = false; + while (!success) { + try { + waiter.wait(); + success = true; + } catch (InterruptedException e) { + } + } + } + } + /** * Move an item in the DB to a new <container, screen, cellX, cellY> */ @@ -1004,9 +1034,11 @@ public class LauncherModel extends BroadcastReceiver { } }); - while (!mStopped && !mLoadAndBindStepFinished) { + while (!mStopped && !mLoadAndBindStepFinished && !mFlushingWorkerThread) { try { - this.wait(); + // Just in case mFlushingWorkerThread changes but we aren't woken up, + // wait no longer than 1sec at a time + this.wait(1000); } catch (InterruptedException ex) { // Ignore } |