Skip to content

Commit

Permalink
修复偶发的线程被取消时, 导致wait()无法释放锁导致图片无法加载的问题.
Browse files Browse the repository at this point in the history
  • Loading branch information
wyouflf committed Jul 26, 2014
1 parent f4f562a commit 30c6cf9
Showing 1 changed file with 5 additions and 4 deletions.
9 changes: 5 additions & 4 deletions library/src/com/lidroid/xutils/bitmap/core/BitmapCache.java
Original file line number Diff line number Diff line change
Expand Up @@ -88,11 +88,9 @@ protected int sizeOf(MemoryCacheKey key, Bitmap bitmap) {
* background thread.
*/
public void initDiskCache() {
if (!globalConfig.isDiskCacheEnabled()) return;

// Set up disk cache
synchronized (mDiskCacheLock) {
if (mDiskLruCache == null || mDiskLruCache.isClosed()) {
if (globalConfig.isDiskCacheEnabled()) {
File diskCacheDir = new File(globalConfig.getDiskCachePath());
if (diskCacheDir.exists() || diskCacheDir.mkdirs()) {
long availableSpace = OtherUtils.getAvailableSpace(diskCacheDir);
Expand Down Expand Up @@ -147,6 +145,7 @@ public Bitmap downloadBitmap(String uri, BitmapDisplayConfig config, final Bitma
try {
mDiskCacheLock.wait();
} catch (Throwable e) {
break;
}
}
}
Expand Down Expand Up @@ -266,6 +265,7 @@ public Bitmap getBitmapFromDiskCache(String uri, BitmapDisplayConfig config) {
try {
mDiskCacheLock.wait();
} catch (Throwable e) {
break;
}
}
}
Expand Down Expand Up @@ -315,14 +315,14 @@ public void clearMemoryCache() {

public void clearDiskCache() {
synchronized (mDiskCacheLock) {
isDiskCacheReady = false;
if (mDiskLruCache != null && !mDiskLruCache.isClosed()) {
try {
mDiskLruCache.delete();
} catch (Throwable e) {
LogUtils.e(e.getMessage(), e);
}
mDiskLruCache = null;
isDiskCacheReady = false;
}
}
initDiskCache();
Expand Down Expand Up @@ -377,6 +377,7 @@ public void flush() {
*/
public void close() {
synchronized (mDiskCacheLock) {
isDiskCacheReady = false;
if (mDiskLruCache != null) {
try {
if (!mDiskLruCache.isClosed()) {
Expand Down

0 comments on commit 30c6cf9

Please sign in to comment.