IOS-1154 finer-grained lock/unlock providing main session
authorDirk Zimmermann <dirk@pep-project.org>
Wed, 11 Jul 2018 18:16:18 +0200
changeset 64219ca3f566cfa
parent 640 4a7ead33bbd9
child 643 ea0df7273ea2
IOS-1154 finer-grained lock/unlock providing main session
pEpObjCAdapter/PEPSessionProvider.m
     1.1 --- a/pEpObjCAdapter/PEPSessionProvider.m	Wed Jul 04 13:21:53 2018 +0200
     1.2 +++ b/pEpObjCAdapter/PEPSessionProvider.m	Wed Jul 11 18:16:18 2018 +0200
     1.3 @@ -27,16 +27,14 @@
     1.4  
     1.5  + (PEPInternalSession * _Nonnull)session
     1.6  {
     1.7 -    [[self sessionForThreadLock] lock];
     1.8 -
     1.9      // Assure a session for the main thread exists and is kept alive before anyother session is created.
    1.10      [self assureSessionForMainThreadExists];
    1.11  
    1.12      if ([NSThread isMainThread]) {
    1.13 -        [[self sessionForThreadLock] unlock];
    1.14          return s_sessionForMainThread;
    1.15      }
    1.16  
    1.17 +    [[self sessionForThreadLock] lock];
    1.18      NSMutableDictionary<PEPCopyableThread*,PEPInternalSession*> *dict = [self sessionForThreadDict];
    1.19      PEPCopyableThread *currentThread = [[PEPCopyableThread alloc] initWithThread:[NSThread currentThread]];
    1.20      PEPInternalSession * __strong newOrExistingSession = dict[currentThread];
    1.21 @@ -108,8 +106,10 @@
    1.22  {
    1.23      // shared code to set global configuration every time
    1.24      void (^configurationBlock)(void) = ^{
    1.25 +        [[self sessionForThreadLock] lock];
    1.26          [self setConfigUnEncryptedSubjectOnSession:s_sessionForMainThread];
    1.27          [self setPassiveModeOnSession:s_sessionForMainThread];
    1.28 +        [[self sessionForThreadLock] unlock];
    1.29      };
    1.30  
    1.31      if (s_sessionForMainThread) {
    1.32 @@ -122,7 +122,9 @@
    1.33          if (s_sessionForMainThread) {
    1.34              return;
    1.35          }
    1.36 +        [[self sessionForThreadLock] lock];
    1.37          s_sessionForMainThread = [PEPInternalSession new];
    1.38 +        [[self sessionForThreadLock] unlock];
    1.39          configurationBlock();
    1.40      };
    1.41