Merge branch 'charlesmchen/databaseViewRegistrationCheckVsConcurrency'
This commit is contained in:
commit
3abcbdf981
@ -22,6 +22,7 @@ extern NSString *const TSSecondaryDevicesDatabaseViewExtensionName;
|
||||
|
||||
- (instancetype)init NS_UNAVAILABLE;
|
||||
|
||||
// This method can be called from any thread.
|
||||
+ (BOOL)hasPendingViewRegistrations;
|
||||
|
||||
// This method must be called _AFTER_ registerThreadInteractionsDatabaseView.
|
||||
|
||||
@ -64,13 +64,29 @@ NSString *const TSSecondaryDevicesDatabaseViewExtensionName = @"TSSecondaryDevic
|
||||
return self;
|
||||
}
|
||||
|
||||
- (BOOL)hasPendingViewRegistrations
|
||||
{
|
||||
@synchronized(self)
|
||||
{
|
||||
return !self.areAllAsyncRegistrationsComplete;
|
||||
}
|
||||
}
|
||||
|
||||
+ (BOOL)hasPendingViewRegistrations
|
||||
{
|
||||
OWSAssert([NSThread isMainThread]);
|
||||
|
||||
return ![TSDatabaseView sharedInstance].areAllAsyncRegistrationsComplete;
|
||||
}
|
||||
|
||||
- (void)setAreAllAsyncRegistrationsComplete
|
||||
{
|
||||
@synchronized(self)
|
||||
{
|
||||
OWSAssert(!self.areAllAsyncRegistrationsComplete);
|
||||
|
||||
self.areAllAsyncRegistrationsComplete = YES;
|
||||
}
|
||||
}
|
||||
|
||||
+ (void)registerMessageDatabaseViewWithName:(NSString *)viewName
|
||||
viewGrouping:(YapDatabaseViewGrouping *)viewGrouping
|
||||
version:(NSString *)version
|
||||
@ -423,8 +439,9 @@ NSString *const TSSecondaryDevicesDatabaseViewExtensionName = @"TSSecondaryDevic
|
||||
// All async registrations are complete when writes are unblocked.
|
||||
[[TSStorageManager sharedManager].newDatabaseConnection
|
||||
asyncReadWriteWithBlock:^(YapDatabaseReadWriteTransaction *_Nonnull transaction) {
|
||||
[TSDatabaseView.sharedInstance setAreAllAsyncRegistrationsComplete];
|
||||
|
||||
dispatch_async(dispatch_get_main_queue(), ^{
|
||||
TSDatabaseView.sharedInstance.areAllAsyncRegistrationsComplete = YES;
|
||||
[[NSNotificationCenter defaultCenter]
|
||||
postNotificationName:kNSNotificationName_DatabaseViewRegistrationComplete
|
||||
object:nil
|
||||
|
||||
Loading…
Reference in New Issue
Block a user