IOSAD-83 unifying adapter locking
authorDirk Zimmermann <dirk@pep-project.org>
Mon, 26 Feb 2018 13:19:19 +0100
changeset 5049fa7b040133c
parent 503 6079df011bd3
child 505 fe0925b145c1
IOSAD-83 unifying adapter locking
pEpObjCAdapter/PEPInternalSession.m
pEpObjCAdapter/PEPObjCAdapter+Internal.h
pEpObjCAdapter/PEPObjCAdapter.m
     1.1 --- a/pEpObjCAdapter/PEPInternalSession.m	Sun Feb 25 10:50:20 2018 +0100
     1.2 +++ b/pEpObjCAdapter/PEPInternalSession.m	Mon Feb 26 13:19:19 2018 +0100
     1.3 @@ -18,8 +18,6 @@
     1.4  #import "PEPMessage.h"
     1.5  #import "NSError+PEP.h"
     1.6  
     1.7 -static NSLock *s_writeLock;
     1.8 -
     1.9  @implementation PEPInternalSession
    1.10  
    1.11  - (instancetype)init
    1.12 @@ -45,10 +43,9 @@
    1.13  {
    1.14      [PEPObjCAdapter unbindSession:self];
    1.15  
    1.16 -    [[PEPObjCAdapter initLock] lock];
    1.17 +    [self lockWrite];
    1.18      release(_session);
    1.19 -    [[PEPObjCAdapter initLock] unlock];
    1.20 -
    1.21 +    [self unlockWrite];
    1.22  }
    1.23  
    1.24  #pragma mark - CONFIG
    1.25 @@ -60,6 +57,16 @@
    1.26  
    1.27  #pragma mark - INTERNAL
    1.28  
    1.29 +- (void)lockWrite
    1.30 +{
    1.31 +    [PEPObjCAdapter lockWrite];
    1.32 +}
    1.33 +
    1.34 +- (void)unlockWrite
    1.35 +{
    1.36 +    [PEPObjCAdapter unlockWrite];
    1.37 +}
    1.38 +
    1.39  + (void)setupTrustWordsDB
    1.40  {
    1.41      static dispatch_once_t once;
    1.42 @@ -68,16 +75,6 @@
    1.43      });
    1.44  }
    1.45  
    1.46 -- (void)lockWrite
    1.47 -{
    1.48 -    [s_writeLock lock];
    1.49 -}
    1.50 -
    1.51 -- (void)unlockWrite
    1.52 -{
    1.53 -    [s_writeLock unlock];
    1.54 -}
    1.55 -
    1.56  #pragma mark - DEBUG UTILS
    1.57  
    1.58  /**
    1.59 @@ -545,8 +542,6 @@
    1.60  
    1.61  + (void)initialize
    1.62  {
    1.63 -    s_writeLock = [[NSLock alloc] init];
    1.64 -
    1.65      NSDictionary *ratingToStringIntern =
    1.66      @{
    1.67        [NSNumber numberWithInteger:PEP_rating_cannot_decrypt]: @"cannot_decrypt",
     2.1 --- a/pEpObjCAdapter/PEPObjCAdapter+Internal.h	Sun Feb 25 10:50:20 2018 +0100
     2.2 +++ b/pEpObjCAdapter/PEPObjCAdapter+Internal.h	Mon Feb 26 13:19:19 2018 +0100
     2.3 @@ -23,11 +23,6 @@
     2.4   */
     2.5  + (BOOL)unecryptedSubjectEnabled;
     2.6  
     2.7 -/**
     2.8 - The lock that should be used for locking all session init() and release().
     2.9 - */
    2.10 -+ (NSLock *)initLock;
    2.11 -
    2.12  // this messages are for internal use only; do not call
    2.13  
    2.14  + (void)registerExamineFunction:(PEP_SESSION)session;
    2.15 @@ -38,6 +33,16 @@
    2.16  + (void)bindSession:(PEPInternalSession*)session;
    2.17  + (void)unbindSession:(PEPInternalSession*)session;
    2.18  
    2.19 +/**
    2.20 + Locks for (potential) sqlite writes.
    2.21 + */
    2.22 ++ (void)lockWrite;
    2.23 +
    2.24 +/**
    2.25 + Unlocks (potential) sqlite writes.
    2.26 + */
    2.27 ++ (void)unlockWrite;
    2.28 +
    2.29  @end
    2.30  
    2.31  #endif /* PEPIOSAdapter_Internal_h */
     3.1 --- a/pEpObjCAdapter/PEPObjCAdapter.m	Sun Feb 25 10:50:20 2018 +0100
     3.2 +++ b/pEpObjCAdapter/PEPObjCAdapter.m	Mon Feb 26 13:19:19 2018 +0100
     3.3 @@ -103,7 +103,7 @@
     3.4  
     3.5  const char* _Nullable SystemDB = NULL;
     3.6  NSURL *s_homeURL;
     3.7 -static NSLock *s_initLock;
     3.8 +static NSLock *s_writeLock;
     3.9  static BOOL s_unecryptedSubjectEnabled = NO;
    3.10  
    3.11  @implementation PEPObjCAdapter
    3.12 @@ -126,12 +126,7 @@
    3.13  {
    3.14      s_homeURL = [self createApplicationDirectory];
    3.15      [self setHomeDirectory:s_homeURL]; // Important, defines $HOME and $TEMP for the engine
    3.16 -    s_initLock = [[NSLock alloc] init];
    3.17 -}
    3.18 -
    3.19 -+ (NSLock *)initLock
    3.20 -{
    3.21 -    return s_initLock;
    3.22 +    s_writeLock = [[NSLock alloc] init];
    3.23  }
    3.24  
    3.25  + (NSURL *)homeURL
    3.26 @@ -251,6 +246,20 @@
    3.27      return boundSessions;
    3.28  }
    3.29  
    3.30 +#pragma mark - sqlite locking
    3.31 +
    3.32 ++ (void)lockWrite
    3.33 +{
    3.34 +    [s_writeLock lock];
    3.35 +}
    3.36 +
    3.37 ++ (void)unlockWrite
    3.38 +{
    3.39 +    [s_writeLock unlock];
    3.40 +}
    3.41 +
    3.42 +#pragma mark - Old keysync implementation
    3.43 +
    3.44  ///////////////////////////////////////////////////////////////////////////////
    3.45  //  Keyserver and Identity lookup - ObjC part
    3.46  
    3.47 @@ -357,9 +366,9 @@
    3.48          
    3.49          syncThreadJoinCond = [[NSConditionLock alloc] initWithCondition:NO];
    3.50          
    3.51 -        [[PEPObjCAdapter initLock] lock];
    3.52 +        [self lockWrite];
    3.53          PEP_STATUS status = init(&sync_session);
    3.54 -        [[PEPObjCAdapter initLock] unlock];
    3.55 +        [self unlockWrite];
    3.56          if (status != PEP_STATUS_OK) {
    3.57              return;
    3.58          }
    3.59 @@ -415,10 +424,10 @@
    3.60          [syncThreadJoinCond lockWhenCondition:YES];
    3.61          [syncThreadJoinCond unlock];
    3.62          
    3.63 -        [[PEPObjCAdapter initLock] lock];
    3.64 +        [self lockWrite];
    3.65          release(sync_session);
    3.66 -        [[PEPObjCAdapter initLock] unlock];
    3.67 -        
    3.68 +        [self unlockWrite];
    3.69 +
    3.70          sync_session = NULL;
    3.71          syncThread = nil;
    3.72          syncQueue = nil;