Permalink
Browse files

Expand a mutex lock because it previously did not cover all possible …

…multithreading cases
  • Loading branch information...
dmoagx committed May 6, 2017
1 parent 994ff16 commit 9d8926a9da1b2325a2139c5e23146f03ccc17003
Showing with 26 additions and 17 deletions.
  1. +26 −17 Source/SPDataStorage.m
View
@@ -59,33 +59,38 @@ @implementation SPDataStorage
*/
- (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 @@ - (void) awaitDataDownloaded
- (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];
}

0 comments on commit 9d8926a

Please sign in to comment.