Permalink
Browse files

Move some code to a place where it makes more sense to be (part of #2770

)

(This should not cause any behavioral changes)
  • Loading branch information...
dmoagx committed Apr 17, 2017
1 parent 4daa0e1 commit e1b881b8f893803c4949a69055c4e8106562327d
Showing with 20 additions and 11 deletions.
  1. +0 −1 Source/SPCustomQuery.h
  2. +1 −10 Source/SPCustomQuery.m
  3. +7 −0 Source/SPDataStorage.h
  4. +12 −0 Source/SPDataStorage.m
View
@@ -160,7 +160,6 @@
SPDataStorage *resultData;
pthread_mutex_t resultDataLock;
NSCondition *resultLoadingCondition;
NSInteger resultDataCount;
NSArray *cqColumnDefinition;
NSString *lastExecutedQuery;
View
@@ -993,11 +993,7 @@ - (void)updateResultStore:(SPMySQLStreamingResultStore *)theResultStore
// Set up the table updates timer and wait for it to notify this thread about completion
[[self onMainThread] initQueryLoadTimer];
[resultLoadingCondition lock];
while (![resultData dataDownloaded]) {
[resultLoadingCondition waitUntilDate:[NSDate dateWithTimeIntervalSinceNow:0.05]];
}
[resultLoadingCondition unlock];
[resultData awaitDataDownloaded];
// If the final column autoresize wasn't performed, perform it
if (queryLoadLastRowCount < 200) [[self onMainThread] autosizeColumns];
@@ -1500,10 +1496,7 @@ - (void) queryLoadUpdate:(NSTimer *)theTimer
}
if ([resultData dataDownloaded]) {
[resultLoadingCondition lock];
[resultLoadingCondition signal];
[self clearQueryLoadTimer];
[resultLoadingCondition unlock];
}
// Check whether a table update is required, based on whether new rows are
@@ -3787,7 +3780,6 @@ - (id)init
runPrimaryActionButtonAsSelection = nil;
queryLoadTimer = nil;
resultLoadingCondition = [NSCondition new];
prefs = [NSUserDefaults standardUserDefaults];
@@ -4070,7 +4062,6 @@ - (void)dealloc
[NSObject cancelPreviousPerformRequestsWithTarget:customQueryView];
[self clearQueryLoadTimer];
SPClear(resultLoadingCondition);
SPClear(usedQuery);
SPClear(lastExecutedQuery);
SPClear(resultData);
View
@@ -44,6 +44,7 @@
SPMySQLStreamingResultStore *dataStorage;
NSPointerArray *editedRows;
BOOL *unloadedColumns;
NSCondition *dataDownloadedLock;
NSUInteger numberOfColumns;
NSUInteger editedRowCount;
@@ -75,6 +76,12 @@
- (NSUInteger) columnCount;
- (BOOL) dataDownloaded;
/**
* This method will block the caller until -dataDownloaded returns YES.
* Multiple parallel calls from different threads are possible.
*/
- (void) awaitDataDownloaded;
/* Delegate callback methods */
- (void)resultStoreDidFinishLoadingData:(SPMySQLStreamingResultStore *)resultStore;
View
@@ -468,6 +468,13 @@ - (BOOL) dataDownloaded
}
}
- (void) awaitDataDownloaded
{
[dataDownloadedLock lock];
while(![self dataDownloaded]) [dataDownloadedLock wait];
[dataDownloadedLock unlock];
}
#pragma mark - Delegate callback methods
/**
@@ -479,6 +486,9 @@ - (void)resultStoreDidFinishLoadingData:(SPMySQLStreamingResultStore *)resultSto
[editedRows setCount:(NSUInteger)[resultStore numberOfRows]];
editedRowCount = [editedRows count];
}
[dataDownloadedLock lock];
[dataDownloadedLock broadcast];
[dataDownloadedLock unlock];
}
/**
@@ -492,6 +502,7 @@ - (id) init
dataStorage = nil;
editedRows = nil;
unloadedColumns = NULL;
dataDownloadedLock = [NSCondition new];
numberOfColumns = 0;
editedRowCount = 0;
@@ -504,6 +515,7 @@ - (void) dealloc
@synchronized(self) {
SPClear(dataStorage);
SPClear(editedRows);
SPClear(dataDownloadedLock);
if (unloadedColumns) {
free(unloadedColumns), unloadedColumns = NULL;
}

0 comments on commit e1b881b

Please sign in to comment.