aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorMax <post@wickenrode.com>2017-04-18 00:33:14 +0200
committerMax <post@wickenrode.com>2017-04-18 00:33:14 +0200
commite1b881b8f893803c4949a69055c4e8106562327d (patch)
treec4a06dc86700c5fb0e25d47a54061117e0d7f0f1
parent4daa0e1419ac63abcfb87b9ba7e9f3db5861a95a (diff)
downloadsequelpro-e1b881b8f893803c4949a69055c4e8106562327d.tar.gz
sequelpro-e1b881b8f893803c4949a69055c4e8106562327d.tar.bz2
sequelpro-e1b881b8f893803c4949a69055c4e8106562327d.zip
Move some code to a place where it makes more sense to be (part of #2770)
(This should not cause any behavioral changes)
-rw-r--r--Source/SPCustomQuery.h1
-rw-r--r--Source/SPCustomQuery.m11
-rw-r--r--Source/SPDataStorage.h7
-rw-r--r--Source/SPDataStorage.m12
4 files changed, 20 insertions, 11 deletions
diff --git a/Source/SPCustomQuery.h b/Source/SPCustomQuery.h
index e976f716..b63de32f 100644
--- a/Source/SPCustomQuery.h
+++ b/Source/SPCustomQuery.h
@@ -160,7 +160,6 @@
SPDataStorage *resultData;
pthread_mutex_t resultDataLock;
- NSCondition *resultLoadingCondition;
NSInteger resultDataCount;
NSArray *cqColumnDefinition;
NSString *lastExecutedQuery;
diff --git a/Source/SPCustomQuery.m b/Source/SPCustomQuery.m
index 591bcb12..38c593d1 100644
--- a/Source/SPCustomQuery.m
+++ b/Source/SPCustomQuery.m
@@ -993,11 +993,7 @@
// 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 @@
}
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 @@
runPrimaryActionButtonAsSelection = nil;
queryLoadTimer = nil;
- resultLoadingCondition = [NSCondition new];
prefs = [NSUserDefaults standardUserDefaults];
@@ -4070,7 +4062,6 @@
[NSObject cancelPreviousPerformRequestsWithTarget:customQueryView];
[self clearQueryLoadTimer];
- SPClear(resultLoadingCondition);
SPClear(usedQuery);
SPClear(lastExecutedQuery);
SPClear(resultData);
diff --git a/Source/SPDataStorage.h b/Source/SPDataStorage.h
index bb45f71b..23c7e124 100644
--- a/Source/SPDataStorage.h
+++ b/Source/SPDataStorage.h
@@ -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;
diff --git a/Source/SPDataStorage.m b/Source/SPDataStorage.m
index fca33c0a..44c2dc9d 100644
--- a/Source/SPDataStorage.m
+++ b/Source/SPDataStorage.m
@@ -468,6 +468,13 @@ static inline NSMutableArray* SPDataStorageGetEditedRow(NSPointerArray* rowStore
}
}
+- (void) awaitDataDownloaded
+{
+ [dataDownloadedLock lock];
+ while(![self dataDownloaded]) [dataDownloadedLock wait];
+ [dataDownloadedLock unlock];
+}
+
#pragma mark - Delegate callback methods
/**
@@ -479,6 +486,9 @@ static inline NSMutableArray* SPDataStorageGetEditedRow(NSPointerArray* rowStore
[editedRows setCount:(NSUInteger)[resultStore numberOfRows]];
editedRowCount = [editedRows count];
}
+ [dataDownloadedLock lock];
+ [dataDownloadedLock broadcast];
+ [dataDownloadedLock unlock];
}
/**
@@ -492,6 +502,7 @@ static inline NSMutableArray* SPDataStorageGetEditedRow(NSPointerArray* rowStore
dataStorage = nil;
editedRows = nil;
unloadedColumns = NULL;
+ dataDownloadedLock = [NSCondition new];
numberOfColumns = 0;
editedRowCount = 0;
@@ -504,6 +515,7 @@ static inline NSMutableArray* SPDataStorageGetEditedRow(NSPointerArray* rowStore
@synchronized(self) {
SPClear(dataStorage);
SPClear(editedRows);
+ SPClear(dataDownloadedLock);
if (unloadedColumns) {
free(unloadedColumns), unloadedColumns = NULL;
}