-
Notifications
You must be signed in to change notification settings - Fork 56
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Fixed race condition in search plugins when canceling old search
- Loading branch information
Showing
20 changed files
with
171 additions
and
44 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,22 @@ | ||
// | ||
// MZBaseSearchProvider.h | ||
// MetaZ | ||
// | ||
// Created by Brian Olsen on 11/05/10. | ||
// Copyright 2010 Maven-Group. All rights reserved. | ||
// | ||
|
||
#import <Cocoa/Cocoa.h> | ||
|
||
|
||
@interface MZBaseSearchProvider : NSObject | ||
{ | ||
@private | ||
id search; | ||
NSMutableArray* canceledSearches; | ||
} | ||
|
||
- (void)cancelSearch; | ||
- (void)startSearch:(id)search; | ||
|
||
@end |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,88 @@ | ||
// | ||
// MZBaseSearchProvider.m | ||
// MetaZ | ||
// | ||
// Created by Brian Olsen on 11/05/10. | ||
// Copyright 2010 Maven-Group. All rights reserved. | ||
// | ||
|
||
#import "MZBaseSearchProvider.h" | ||
#import "GTMNSObject+KeyValueObserving.h" | ||
|
||
@implementation MZBaseSearchProvider | ||
|
||
- (id)init | ||
{ | ||
self = [super init]; | ||
if(self) | ||
{ | ||
canceledSearches = [[NSMutableArray alloc] init]; | ||
} | ||
return self; | ||
} | ||
|
||
- (void)dealloc | ||
{ | ||
//[search gtm_removeObserver:self forKeyPath:@"isFinished" selector:@selector(searchFinished:)]; | ||
for(id canceledSearch in canceledSearches) | ||
[canceledSearch gtm_removeObserver:self forKeyPath:@"isFinished" selector:@selector(canceledSearchFinished:)]; | ||
|
||
[search release]; | ||
[canceledSearches release]; | ||
[super dealloc]; | ||
} | ||
|
||
- (void)cancelSearch | ||
{ | ||
// Finish last search; | ||
if(search) | ||
{ | ||
@synchronized(search) | ||
{ | ||
if(![search isFinished]) | ||
{ | ||
[canceledSearches addObject:search]; | ||
[search gtm_addObserver:self forKeyPath:@"isFinished" selector:@selector(canceledSearchFinished:) userInfo:nil options:0]; | ||
} | ||
//[search gtm_removeObserver:self forKeyPath:@"isFinished" selector:@selector(searchFinished:)]; | ||
} | ||
[search cancel]; | ||
[search release]; | ||
search = nil; | ||
} | ||
} | ||
|
||
- (void)startSearch:(id)theSearch | ||
{ | ||
search = [theSearch retain]; | ||
//[search gtm_addObserver:self forKeyPath:@"isFinished" selector:@selector(searchFinished:) userInfo:nil options:0]; | ||
} | ||
|
||
/* | ||
- (void)searchFinishedMain | ||
{ | ||
[search autorelease]; | ||
search = nil; | ||
} | ||
- (void)searchFinished:(GTMKeyValueChangeNotification *)notification | ||
{ | ||
[search gtm_removeObserver:self forKeyPath:@"isFinished" selector:@selector(searchFinished:)]; | ||
[self performSelectorOnMainThread:@selector(searchFinishedMain) withObject:nil waitUntilDone:YES]; | ||
} | ||
*/ | ||
|
||
- (void)canceledSearchFinishedMain:(id)theSearch | ||
{ | ||
[canceledSearches removeObject:theSearch]; | ||
} | ||
|
||
- (void)canceledSearchFinished:(GTMKeyValueChangeNotification *)notification | ||
{ | ||
[[notification object] gtm_removeObserver:self forKeyPath:@"isFinished" selector:@selector(canceledSearchFinished:)]; | ||
[self performSelectorOnMainThread:@selector(canceledSearchFinishedMain:) | ||
withObject:[notification object] | ||
waitUntilDone:NO]; | ||
} | ||
|
||
@end |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.