Revision: 27948
http://sourceforge.net/p/bibdesk/svn/27948
Author: hofman
Date: 2022-09-28 09:04:11 +0000 (Wed, 28 Sep 2022)
Log Message:
-----------
use readwritelock for server info
Modified Paths:
--------------
trunk/bibdesk/BDSKServerInfo.h
trunk/bibdesk/BDSKServerInfo.m
Modified: trunk/bibdesk/BDSKServerInfo.h
===================================================================
--- trunk/bibdesk/BDSKServerInfo.h 2022-09-28 06:30:34 UTC (rev 27947)
+++ trunk/bibdesk/BDSKServerInfo.h 2022-09-28 09:04:11 UTC (rev 27948)
@@ -45,6 +45,8 @@
BDSKServerTypeDBLP
};
+@class BDSKReadWriteLock;
+
@interface BDSKServerInfo : NSObject <NSCopying, NSMutableCopying, NSCoding> {
NSString *type;
NSString *name;
@@ -54,6 +56,7 @@
NSString *password;
NSMutableDictionary *options;
BOOL passwordInKeychain;
+ BDSKReadWriteLock *passwordLock;
}
+ (id)defaultServerInfoWithType:(NSString *)aType;
Modified: trunk/bibdesk/BDSKServerInfo.m
===================================================================
--- trunk/bibdesk/BDSKServerInfo.m 2022-09-28 06:30:34 UTC (rev 27947)
+++ trunk/bibdesk/BDSKServerInfo.m 2022-09-28 09:04:11 UTC (rev 27948)
@@ -41,6 +41,7 @@
#import "NSString_BDSKExtensions.h"
#import "NSError_BDSKExtensions.h"
#import "BDSKPasswordController.h"
+#import "BDSKReadWriteLock.h"
#define TYPE_KEY @"type"
#define NAME_KEY @"name"
@@ -104,6 +105,7 @@
name = [aName copy];
database = [aDbase copy];
passwordInKeychain = NO;
+ passwordLock = [[BDSKReadWriteLock alloc] init];
if ([self isEntrez] || [self isISI] || [self isDBLP]) {
host = nil;
port = nil;
@@ -167,17 +169,17 @@
- (id)copyWithZone:(NSZone *)aZone {
id copy = nil;
- @synchronized (self) {
- copy = [[BDSKServerInfo allocWithZone:aZone] initWithType:[self type]
name:[self name] database:[self database] host:[self host] port:[self port]
options:options password:password passwordInKeychain:passwordInKeychain];
- }
+ [passwordLock lockForReading];
+ copy = [[BDSKServerInfo allocWithZone:aZone] initWithType:[self type]
name:[self name] database:[self database] host:[self host] port:[self port]
options:options password:password passwordInKeychain:passwordInKeychain];
+ [passwordLock unlock];
return copy;
}
- (id)mutableCopyWithZone:(NSZone *)aZone {
id copy = nil;
- @synchronized (self) {
- copy = [[BDSKMutableServerInfo allocWithZone:aZone] initWithType:[self
type] name:[self name] database:[self database] host:[self host] port:[self
port] options:options password:password passwordInKeychain:passwordInKeychain];
- }
+ [passwordLock lockForReading];
+ copy = [[BDSKMutableServerInfo allocWithZone:aZone] initWithType:[self
type] name:[self name] database:[self database] host:[self host] port:[self
port] options:options password:password passwordInKeychain:passwordInKeychain];
+ [passwordLock unlock];
return copy;
}
@@ -189,6 +191,7 @@
BDSKDESTROY(port);
BDSKDESTROY(options);
BDSKDESTROY(password);
+ BDSKDESTROY(passwordLock);
[super dealloc];
}
@@ -290,10 +293,9 @@
if (usernamePtr)
*usernamePtr = user;
if (passwordPtr) {
- NSString *aPassword = nil;
- @synchronized (self) {
- aPassword = [[password retain] autorelease];
- }
+ [passwordLock lockForReading];
+ NSString *aPassword = [[password retain] autorelease];
+ [passwordLock unlock];
if (aPassword == nil) {
NSString *server = [self isISI] ? ISI_SERVER : [self host];
if (server == nil)
@@ -301,10 +303,11 @@
aPassword = [BDSKPasswordController
passwordForKeychainServer:server port:[[self port] integerValue] account:user];
if (aPassword == nil)
return NO;
- @synchronized (self) {
- passwordInKeychain = YES;
- password = [aPassword copy];
- }
+ [passwordLock lockForWriting];
+ passwordInKeychain = YES;
+ [password release];
+ password = [aPassword copy];
+ [passwordLock unlock];
}
*passwordPtr = aPassword;
}
@@ -315,11 +318,9 @@
if ([self isZoom] == NO && [self isISI] == NO)
return;
// don't get the password from the keychain
- NSString *aPassword = nil;
- @synchronized (self) {
- if (passwordInKeychain == NO)
- aPassword = [[password retain] autorelease];
- }
+ [passwordLock lockForReading];
+ NSString *aPassword = passwordInKeychain ? nil : [[password retain]
autorelease];
+ [passwordLock unlock];
if (aPassword == nil)
return;
NSString *account = [self username];
@@ -327,9 +328,9 @@
if (account == nil || server == nil)
return;
if ([BDSKPasswordController addOrModifyPassword:aPassword
forKeychainServer:server port:[[self port] integerValue] account:account]) {
- @synchronized (self) {
- passwordInKeychain = YES;
- }
+ [passwordLock lockForWriting];
+ passwordInKeychain = YES;
+ [passwordLock unlock];
}
}
This was sent by the SourceForge.net collaborative development platform, the
world's largest Open Source development site.
_______________________________________________
Bibdesk-commit mailing list
[email protected]
https://lists.sourceforge.net/lists/listinfo/bibdesk-commit