IOS-975 s_sessionForMainThread test in the block that creates it
authorDirk Zimmermann <dirk@pep-project.org>
Mon, 19 Mar 2018 12:30:16 +0100
changeset 54809ec46b2113d
parent 547 a0c9be26f48a
child 549 a338e3afd9c2
IOS-975 s_sessionForMainThread test in the block that creates it
pEpObjCAdapter/PEPSessionProvider.m
     1.1 --- a/pEpObjCAdapter/PEPSessionProvider.m	Fri Mar 16 15:16:42 2018 +0100
     1.2 +++ b/pEpObjCAdapter/PEPSessionProvider.m	Mon Mar 19 12:30:16 2018 +0100
     1.3 @@ -94,18 +94,20 @@
     1.4   */
     1.5  + (void)assureSessionForMainThreadExists
     1.6  {
     1.7 -    if (s_sessionForMainThread) {
     1.8 -        return;
     1.9 -    }
    1.10 +    void (^creationBlock)(void) = ^{
    1.11 +        if (s_sessionForMainThread) {
    1.12 +            return;
    1.13 +        }
    1.14 +        s_sessionForMainThread = [PEPInternalSession new];
    1.15 +        [self setConfigUnencryptedSubjectOnSession:s_sessionForMainThread];
    1.16 +    };
    1.17 +
    1.18  
    1.19      if ([NSThread isMainThread]) {
    1.20 -        s_sessionForMainThread = [PEPInternalSession new];
    1.21 +        creationBlock();
    1.22      } else {
    1.23 -        dispatch_sync(dispatch_get_main_queue(), ^{
    1.24 -            s_sessionForMainThread = [PEPInternalSession new];
    1.25 -        });
    1.26 +        dispatch_sync(dispatch_get_main_queue(), creationBlock);
    1.27      }
    1.28 -    [self setConfigUnencryptedSubjectOnSession:s_sessionForMainThread];
    1.29  }
    1.30  
    1.31  + (void)cleanupInternal