aboutsummaryrefslogtreecommitdiff
path: root/src
diff options
context:
space:
mode:
authorScott Jackson <daneren2005@gmail.com>2013-08-25 13:50:30 -0700
committerScott Jackson <daneren2005@gmail.com>2013-08-25 13:50:30 -0700
commit1b58ca11311ad872624a3f84019fbc4e116e241d (patch)
tree04f241c0e4e2037ff14d09b9308153d7a1c8c071 /src
parentabedcbd8d8d1544ffaa237822e0cd2137f0b8bec (diff)
downloaddsub-1b58ca11311ad872624a3f84019fbc4e116e241d.tar.gz
dsub-1b58ca11311ad872624a3f84019fbc4e116e241d.tar.bz2
dsub-1b58ca11311ad872624a3f84019fbc4e116e241d.zip
Remove race condition for access to eventHandler
Diffstat (limited to 'src')
-rw-r--r--src/github/daneren2005/dsub/service/DownloadServiceLifecycleSupport.java26
1 files changed, 10 insertions, 16 deletions
diff --git a/src/github/daneren2005/dsub/service/DownloadServiceLifecycleSupport.java b/src/github/daneren2005/dsub/service/DownloadServiceLifecycleSupport.java
index e0019559..4e3ec29c 100644
--- a/src/github/daneren2005/dsub/service/DownloadServiceLifecycleSupport.java
+++ b/src/github/daneren2005/dsub/service/DownloadServiceLifecycleSupport.java
@@ -117,6 +117,16 @@ public class DownloadServiceLifecycleSupport {
Looper.prepare();
eventLooper = Looper.myLooper();
eventHandler = new Handler(eventLooper);
+
+ // Deserialize queue before starting looper
+ try {
+ lock.lock();
+ deserializeDownloadQueueNow();
+ setup.set(true);
+ } finally {
+ lock.unlock();
+ }
+
Looper.loop();
}
}).start();
@@ -176,8 +186,6 @@ public class DownloadServiceLifecycleSupport {
commandFilter.addAction(DownloadServiceImpl.CMD_NEXT);
downloadService.registerReceiver(intentReceiver, commandFilter);
- deserializeDownloadQueue();
-
new CacheCleaner(downloadService, downloadService).clean();
}
@@ -248,20 +256,6 @@ public class DownloadServiceLifecycleSupport {
FileUtil.serialize(downloadService, state, FILENAME_DOWNLOADS_SER);
}
- private void deserializeDownloadQueue() {
- eventHandler.post(new Runnable() {
- @Override
- public void run() {
- try {
- lock.lock();
- deserializeDownloadQueueNow();
- setup.set(true);
- } finally {
- lock.unlock();
- }
- }
- });
- }
private void deserializeDownloadQueueNow() {
State state = FileUtil.deserialize(downloadService, FILENAME_DOWNLOADS_SER);
if (state == null) {