Welcome to mirror list, hosted at ThFree Co, Russian Federation.

github.com/mono/monodevelop.git - Unnamed repository; edit this file 'description' to name the repository.
summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authortherzok <marius.ungureanu@xamarin.com>2016-10-07 16:54:09 +0300
committertherzok <marius.ungureanu@xamarin.com>2016-10-07 16:55:03 +0300
commitc4516440ba06e607414161fae9838bcf7280543e (patch)
treeebc1b94d90ba5e0d5cb5f7cd23d608d3415f6c29 /main/src/core/MonoDevelop.Ide/MonoDevelop.Components.MainToolbar/FileSearchCategory.cs
parentf220b1a47b71fdd9122aea88cbec1503fa5d470a (diff)
[Misc] Prevent SemaphoreSlim overflow
Release is unsafe when also using Cancellation, so add a check to whether or not we actually hold the lock. A simplified check might be checking for the CurrentCount on the semaphore, but the intent is clearer this way. Bug 45085 - Semaphore overflow in XS on Windows
Diffstat (limited to 'main/src/core/MonoDevelop.Ide/MonoDevelop.Components.MainToolbar/FileSearchCategory.cs')
-rw-r--r--main/src/core/MonoDevelop.Ide/MonoDevelop.Components.MainToolbar/FileSearchCategory.cs13
1 files changed, 8 insertions, 5 deletions
diff --git a/main/src/core/MonoDevelop.Ide/MonoDevelop.Components.MainToolbar/FileSearchCategory.cs b/main/src/core/MonoDevelop.Ide/MonoDevelop.Components.MainToolbar/FileSearchCategory.cs
index eae4e86ec8..9d6b8b959a 100644
--- a/main/src/core/MonoDevelop.Ide/MonoDevelop.Components.MainToolbar/FileSearchCategory.cs
+++ b/main/src/core/MonoDevelop.Ide/MonoDevelop.Components.MainToolbar/FileSearchCategory.cs
@@ -104,17 +104,20 @@ namespace MonoDevelop.Components.MainToolbar
public override Task GetResults (ISearchResultCallback searchResultCallback, SearchPopupSearchPattern pattern, CancellationToken token)
{
return Task.Run (async delegate {
- List<Tuple<string, string, ProjectFile>> files;
- //This lock is here in case user quickly types 5 letters which triggers 5 threads
- //we don't want to use all CPU doing same thing, instead 1st one will create cache, others will wait here
- //and then all will use cached version...
+ List<Tuple<string, string, ProjectFile>> files;
+ //This lock is here in case user quickly types 5 letters which triggers 5 threads
+ //we don't want to use all CPU doing same thing, instead 1st one will create cache, others will wait here
+ //and then all will use cached version...
+ bool locked = false;
try {
await allFilesLock.WaitAsync (token);
+ locked = true;
files = allFilesCache = allFilesCache ?? GenerateAllFiles ();
if (token.IsCancellationRequested)
return;
} finally {
- allFilesLock.Release ();
+ if (locked)
+ allFilesLock.Release ();
}
var matcher = StringMatcher.GetMatcher (pattern.Pattern, false);