diff options
author | Max <post@wickenrode.com> | 2017-05-06 23:55:56 +0200 |
---|---|---|
committer | Max <post@wickenrode.com> | 2017-05-06 23:55:56 +0200 |
commit | 9d8926a9da1b2325a2139c5e23146f03ccc17003 (patch) | |
tree | fd769e689f84fb25b5b7a414007aa5e1f403ebd7 /Source | |
parent | 994ff166120054a2ca2f198fd42b9c1bfc374a28 (diff) | |
download | sequelpro-9d8926a9da1b2325a2139c5e23146f03ccc17003.tar.gz sequelpro-9d8926a9da1b2325a2139c5e23146f03ccc17003.tar.bz2 sequelpro-9d8926a9da1b2325a2139c5e23146f03ccc17003.zip |
Expand a mutex lock because it previously did not cover all possible multithreading cases
Diffstat (limited to 'Source')
-rw-r--r-- | Source/SPDataStorage.m | 43 |
1 files changed, 26 insertions, 17 deletions
diff --git a/Source/SPDataStorage.m b/Source/SPDataStorage.m index a9a608f1..5db56b1e 100644 --- a/Source/SPDataStorage.m +++ b/Source/SPDataStorage.m @@ -59,33 +59,38 @@ static inline NSMutableArray* SPDataStorageGetEditedRow(NSPointerArray* rowStore */ - (void) setDataStorage:(SPMySQLStreamingResultStore *)newDataStorage updatingExisting:(BOOL)updateExistingStore { - SPMySQLStreamingResultStore *oldDataStorage = dataStorage; + BOOL *oldUnloadedColumns; + NSPointerArray *oldEditedRows; + SPMySQLStreamingResultStore *oldDataStorage; + + @synchronized(self) { + oldDataStorage = dataStorage; - if (oldDataStorage) { - // If the table is reloading data, link to the current data store for smoother loads - if (updateExistingStore) { - [newDataStorage replaceExistingResultStore:oldDataStorage]; + if (oldDataStorage) { + // If the table is reloading data, link to the current data store for smoother loads + if (updateExistingStore) { + [newDataStorage replaceExistingResultStore:oldDataStorage]; + } } - } - [newDataStorage retain]; + [newDataStorage retain]; - NSPointerArray *newEditedRows = [[NSPointerArray alloc] init]; - NSUInteger newNumberOfColumns = [newDataStorage numberOfFields]; - BOOL *newUnloadedColumns = calloc(newNumberOfColumns, sizeof(BOOL)); - for (NSUInteger i = 0; i < newNumberOfColumns; i++) { - newUnloadedColumns[i] = NO; - } - - BOOL *oldUnloadedColumns = unloadedColumns; - NSPointerArray *oldEditedRows = editedRows; - @synchronized(self) { + NSPointerArray *newEditedRows = [[NSPointerArray alloc] init]; + NSUInteger newNumberOfColumns = [newDataStorage numberOfFields]; + BOOL *newUnloadedColumns = calloc(newNumberOfColumns, sizeof(BOOL)); + for (NSUInteger i = 0; i < newNumberOfColumns; i++) { + newUnloadedColumns[i] = NO; + } + + oldUnloadedColumns = unloadedColumns; + oldEditedRows = editedRows; dataStorage = newDataStorage; numberOfColumns = newNumberOfColumns; unloadedColumns = newUnloadedColumns; editedRowCount = 0; editedRows = newEditedRows; } + free(oldUnloadedColumns); [oldEditedRows release]; [oldDataStorage release]; @@ -509,6 +514,10 @@ static inline NSMutableArray* SPDataStorageGetEditedRow(NSPointerArray* rowStore - (void)resultStoreDidFinishLoadingData:(SPMySQLStreamingResultStore *)resultStore { @synchronized(self) { + if(resultStore != dataStorage) { + NSLog(@"%s: received delegate callback from an unknown result store %p (expected: %p). Ignored!", __PRETTY_FUNCTION__, resultStore, dataStorage); + return; + } [editedRows setCount:(NSUInteger)[resultStore numberOfRows]]; editedRowCount = [editedRows count]; } |