[Android] ThumbnailerManager: interrupt the thread when calling stop()
Ludovic Fauvet
git at videolan.org
Tue Oct 2 01:38:16 CEST 2012
vlc-ports/android | branch: master | Ludovic Fauvet <etix at videolan.org> | Tue Oct 2 01:21:14 2012 +0200| [05acaeaa4ef0fbcf373617fe9cda529f3a723cde] | committer: Ludovic Fauvet
ThumbnailerManager: interrupt the thread when calling stop()
This fixes the issue where the ThumbnailerManager was generating only a
single thumbnail before stopping unexpectedly. Without a explicit call
to stop().
The reason of the issue was that the thread was sleeping (waiting for
new jobs) and stopped while being in that state. Later, when a new job
was added the thread woke up and stopped after the first thumbnail as
requested previously.
> http://git.videolan.org/gitweb.cgi/vlc-ports/android.git/?a=commit;h=05acaeaa4ef0fbcf373617fe9cda529f3a723cde
---
vlc-android/src/org/videolan/vlc/ThumbnailerManager.java | 13 +++++++++----
1 file changed, 9 insertions(+), 4 deletions(-)
diff --git a/vlc-android/src/org/videolan/vlc/ThumbnailerManager.java b/vlc-android/src/org/videolan/vlc/ThumbnailerManager.java
index 3d41877..15ff40d 100644
--- a/vlc-android/src/org/videolan/vlc/ThumbnailerManager.java
+++ b/vlc-android/src/org/videolan/vlc/ThumbnailerManager.java
@@ -70,10 +70,10 @@ public class ThumbnailerManager implements Runnable {
}
public void start(VideoListFragment videoListFragment) {
+ isStopping = false;
if (mThread == null || mThread.getState() == State.TERMINATED) {
mVideoListFragment = videoListFragment;
mVideoListFragment.setThumbnailerManager(this);
- isStopping = false;
mThread = new Thread(this);
mThread.start();
}
@@ -81,6 +81,7 @@ public class ThumbnailerManager implements Runnable {
public void stop() {
isStopping = true;
+ mThread.interrupt();
}
/**
@@ -121,7 +122,7 @@ public class ThumbnailerManager implements Runnable {
while (!isStopping) {
lock.lock();
// Get the id of the file browser item to create its thumbnail.
- boolean killed = false;
+ boolean interrupted = false;
while (mItems.size() == 0) {
try {
MainActivity.hideProgressBar(mContext);
@@ -129,11 +130,12 @@ public class ThumbnailerManager implements Runnable {
totalCount = 0;
notEmpty.await();
} catch (InterruptedException e) {
- killed = true;
+ interrupted = true;
+ Log.i(TAG, "interruption probably requested by stop()");
break;
}
}
- if (killed) {
+ if (interrupted) {
lock.unlock();
break;
}
@@ -172,8 +174,11 @@ public class ThumbnailerManager implements Runnable {
try {
mVideoListFragment.await();
} catch (InterruptedException e) {
+ Log.i(TAG, "interruption probably requested by stop()");
break;
} catch (BrokenBarrierException e) {
+ Log.e(TAG, "Unexpected BrokenBarrierException");
+ e.printStackTrace();
break;
}
}
More information about the Android
mailing list