Changeset 85

Show
Ignore:
Timestamp:
12/27/05 17:24:53 (3 years ago)
Author:
mrowe
Message:

There's no need for one lock per member variable. Using a single lock for the getter/setters cleans the code up a little more.

Files:

Legend:

Unmodified
Added
Removed
Modified
Copied
Moved
  • trunk/Libs/SSHAgent.h

    r83 r85  
    1111        NSArray *keysOnAgent; 
    1212 
    13         /* Locks */ 
    14         NSLock *socketPathLock; 
    15         NSLock *agentSocketPathLock; 
    16         NSLock *keysOnAgentLock; 
    17         NSLock *thePIDLock; 
     13        NSLock *agentLock; 
    1814} 
    1915 
  • trunk/Libs/SSHAgent.m

    r84 r85  
    5252                selector:@selector(keysOnAgentStatusChange:) name:@"KeysOnAgentUnknown" object:nil]; 
    5353         
    54         socketPathLock = [[NSLock alloc] init]; 
    55         agentSocketPathLock = [[NSLock alloc] init]; 
    56         keysOnAgentLock = [[NSLock alloc] init]; 
    57         thePIDLock = [[NSLock alloc] init]; 
     54        agentLock = [[NSLock alloc] init]; 
    5855         
    5956        return self; 
     
    6461        currentAgent = nil; 
    6562 
    66         [socketPathLock dealloc]; 
    67         [agentSocketPathLock dealloc]; 
    68         [keysOnAgentLock dealloc]; 
    69         [thePIDLock dealloc]; 
     63        [agentLock release]; 
    7064 
    7165        [super dealloc]; 
     
    8175        } 
    8276 
    83         [socketPathLock lock]; 
     77        [agentLock lock]; 
    8478        NSString *oldPath = socketPath; 
    8579        socketPath = [path copy]; 
    8680        [oldPath release]; 
    87         [socketPathLock unlock]; 
     81        [agentLock unlock]; 
    8882} 
    8983 
     
    9185- (NSString *)socketPath 
    9286{ 
    93         [socketPathLock lock]; 
     87        [agentLock lock]; 
    9488        NSString *returnString = [[socketPath copy] autorelease]; 
    95         [socketPathLock unlock]; 
     89        [agentLock unlock]; 
    9690 
    9791        return returnString; 
     
    10195- (void)setAgentSocketPath:(NSString *)path 
    10296{ 
    103         [agentSocketPathLock lock]; 
     97        [agentLock lock]; 
    10498        NSString *oldPath = agentSocketPath; 
    10599        agentSocketPath = [path copy]; 
    106100        [oldPath release]; 
    107         [agentSocketPathLock unlock]; 
     101        [agentLock unlock]; 
    108102} 
    109103 
     
    111105- (NSString *)agentSocketPath 
    112106{ 
    113         [agentSocketPathLock lock]; 
     107        [agentLock lock]; 
    114108        NSString *returnString = [[agentSocketPath copy] autorelease]; 
    115         [agentSocketPathLock unlock]; 
     109        [agentLock unlock]; 
    116110 
    117111        return returnString; 
     
    128122- (int)PID 
    129123{ 
    130         [thePIDLock lock]; 
     124        [agentLock lock]; 
    131125        int returnInt = thePID; 
    132         [thePIDLock unlock]; 
     126        [agentLock unlock]; 
    133127 
    134128        return returnInt; 
     
    137131- (void) setPID:(int)pid 
    138132{ 
    139         [thePIDLock lock]; 
     133        [agentLock lock]; 
    140134        thePID = pid; 
    141         [thePIDLock unlock]; 
     135        [agentLock unlock]; 
    142136} 
    143137 
     
    145139- (NSArray *)keysOnAgent 
    146140{ 
    147         [keysOnAgentLock lock]; 
     141        [agentLock lock]; 
    148142        NSArray *returnArray = [[keysOnAgent copy] autorelease]; 
    149         [keysOnAgentLock unlock]; 
     143        [agentLock unlock]; 
    150144 
    151145        return returnArray; 
     
    154148- (void) setKeysOnAgent:(NSArray *)keys 
    155149{ 
    156         [keysOnAgentLock lock]; 
     150        [agentLock lock]; 
    157151        NSArray *oldKeys = keysOnAgent; 
    158152        keysOnAgent = [keys copy]; 
    159153        [oldKeys release]; 
    160         [keysOnAgentLock unlock]; 
     154        [agentLock unlock]; 
    161155} 
    162156