• R/O
  • HTTP
  • SSH
  • HTTPS

Commit

Tags
No Tags

Frequently used words (click to add to your profile)

javac++androidlinuxc#windowsobjective-ccocoa誰得qtpythonphprubygameguibathyscaphec計画中(planning stage)翻訳omegatframeworktwitterdomtestvb.netdirectxゲームエンジンbtronarduinopreviewer

dev


Commit MetaInfo

Revision6d40a276c6d9f663e282667080868ad3e5f1ab10 (tree)
Time2013-04-10 09:56:09
AuthorKimura Youichi <kim.upsilon@bucy...>
CommiterKimura Youichi

Log Message

Revert "ImageCacheの排他制御を改善"

This reverts commit f3d6eb2556e7739b167f1f4fd79251b1bb660ac8.

LRUCacheDictionaryは参照もスレッドセーフではないため。

Change Summary

Incremental Difference

--- a/OpenTween/ImageCache.cs
+++ b/OpenTween/ImageCache.cs
@@ -45,7 +45,7 @@ namespace OpenTween
4545 /// <summary>
4646 /// innerDictionary の排他制御のためのロックオブジェクト
4747 /// </summary>
48- private ReaderWriterLockSlim lockObject = new ReaderWriterLockSlim();
48+ private object lockObject = new object();
4949
5050 /// <summary>
5151 /// オブジェクトが破棄された否か
@@ -54,13 +54,11 @@ namespace OpenTween
5454
5555 public ImageCache()
5656 {
57- this.lockObject.EnterWriteLock();
58- try
57+ lock (this.lockObject)
5958 {
6059 this.innerDictionary = new LRUCacheDictionary<string, Task<MemoryImage>>(trimLimit: 300, autoTrimCount: 100);
6160
62- this.innerDictionary.CacheRemoved += (s, e) =>
63- {
61+ this.innerDictionary.CacheRemoved += (s, e) => {
6462 // まだ参照されている場合もあるのでDisposeはファイナライザ任せ
6563
6664 this.CacheRemoveCount++;
@@ -68,7 +66,6 @@ namespace OpenTween
6866
6967 this.cancelTokenSource = new CancellationTokenSource();
7068 }
71- finally { this.lockObject.ExitWriteLock(); }
7269 }
7370
7471 /// <summary>
@@ -98,10 +95,12 @@ namespace OpenTween
9895 return Task.Factory.StartNew(() =>
9996 {
10097 Task<MemoryImage> cachedImageTask = null;
101- this.lockObject.EnterUpgradeableReadLock();
102- try
98+ lock (this.lockObject)
10399 {
104- if (!force && this.innerDictionary.ContainsKey(address) && !this.innerDictionary[address].IsFaulted)
100+ if (force)
101+ this.innerDictionary.Remove(address);
102+
103+ if (this.innerDictionary.ContainsKey(address) && !this.innerDictionary[address].IsFaulted)
105104 cachedImageTask = this.innerDictionary[address];
106105
107106 if (cachedImageTask != null)
@@ -109,41 +108,34 @@ namespace OpenTween
109108
110109 cancelToken.ThrowIfCancellationRequested();
111110
112- this.lockObject.EnterWriteLock();
113- try
111+ using (var client = new OTWebClient() { Timeout = 10000 })
114112 {
115- using (var client = new OTWebClient() { Timeout = 10000 })
113+ var imageTask = client.DownloadDataAsync(new Uri(address), cancelToken).ContinueWith(t =>
116114 {
117- var imageTask = client.DownloadDataAsync(new Uri(address), cancelToken).ContinueWith(t =>
115+ MemoryImage image = null;
116+ if (t.Status == TaskStatus.RanToCompletion)
118117 {
119- MemoryImage image = null;
120- if (t.Status == TaskStatus.RanToCompletion)
121- {
122- image = MemoryImage.CopyFromBytes(t.Result);
123- }
118+ image = MemoryImage.CopyFromBytes(t.Result);
119+ }
124120
125- if (t.Exception != null)
126- t.Exception.Handle(e => e is WebException);
121+ if (t.Exception != null)
122+ t.Exception.Handle(e => e is WebException);
127123
128- // FIXME: MemoryImage.Dispose() が正しいタイミングで呼ばれるように修正すべき
129- return image;
130- }, cancelToken);
124+ // FIXME: MemoryImage.Dispose() が正しいタイミングで呼ばれるように修正すべき
125+ return image;
126+ }, cancelToken);
131127
132- this.innerDictionary[address] = imageTask;
128+ this.innerDictionary[address] = imageTask;
133129
134- return imageTask;
135- }
130+ return imageTask;
136131 }
137- finally { this.lockObject.ExitWriteLock(); }
138132 }
139- finally { this.lockObject.ExitUpgradeableReadLock(); }
140133 }, cancelToken).Unwrap();
141134 }
142135
143136 public MemoryImage TryGetFromCache(string address)
144137 {
145- this.lockObject.EnterReadLock();
146- try
138+ lock (this.lockObject)
147139 {
148140 if (!this.innerDictionary.ContainsKey(address))
149141 return null;
@@ -154,18 +146,15 @@ namespace OpenTween
154146
155147 return imageTask.Result;
156148 }
157- finally { this.lockObject.ExitReadLock(); }
158149 }
159150
160151 public void CancelAsync()
161152 {
162- this.lockObject.EnterWriteLock();
163- try
153+ lock (this.lockObject)
164154 {
165155 this.cancelTokenSource.Cancel();
166156 this.cancelTokenSource = new CancellationTokenSource();
167157 }
168- finally { this.lockObject.ExitWriteLock(); }
169158 }
170159
171160 protected virtual void Dispose(bool disposing)
@@ -176,8 +165,7 @@ namespace OpenTween
176165 {
177166 this.CancelAsync();
178167
179- this.lockObject.EnterWriteLock();
180- try
168+ lock (this.lockObject)
181169 {
182170 foreach (var item in this.innerDictionary)
183171 {
@@ -189,9 +177,6 @@ namespace OpenTween
189177 this.innerDictionary.Clear();
190178 this.cancelTokenSource.Dispose();
191179 }
192- finally { this.lockObject.ExitWriteLock(); }
193-
194- this.lockObject.Dispose();
195180 }
196181 }
197182
--- a/OpenTween/Resources/ChangeLog.txt
+++ b/OpenTween/Resources/ChangeLog.txt
@@ -2,7 +2,6 @@
22
33 ==== Ver 1.1.0-beta1(2013/xx/xx)
44 * NEW: タブの表示位置を画面上部に変更可能に (thx @aokomoriuta!)
5- * CHG: アイコン読み込み処理の速度改善
65 * FIX: スペースが含まれているURLをブラウザで開こうとするとURLが分断されて複数のタブが開いてしまう問題を修正 (thx @5px!)
76 * FIX: 画面更新時にInvalidOperationExceptionのエラーが発生する不具合を修正
87