diff --git a/ChangeLog b/ChangeLog index a5ad10f3f..51b2a8926 100644 --- a/ChangeLog +++ b/ChangeLog @@ -1,3 +1,9 @@ +2003-04-27 Richard Frith-Macdonald + + * Source/NSUserDefaults.m: ([synchronize]) fix locking to permit + recursive call to this method, ensuring the distributed lock is + only obtained once. + 2003-04-17 Richard Frith-Macdonald * Headers/gnustep/base/GSCategories.h: diff --git a/Source/NSDistributedLock.m b/Source/NSDistributedLock.m index 64118a678..24c10c309 100644 --- a/Source/NSDistributedLock.m +++ b/Source/NSDistributedLock.m @@ -138,7 +138,7 @@ static NSFileManager *mgr = nil; } /** - * Returns the date at which the lock was aquired by any + * Returns the date at which the lock was aquired by any * NSDistributedLock using the same path. If nothing has * the lock, this returns nil. */ diff --git a/Source/NSUserDefaults.m b/Source/NSUserDefaults.m index c27080d4a..1fc40ea65 100644 --- a/Source/NSUserDefaults.m +++ b/Source/NSUserDefaults.m @@ -1321,10 +1321,13 @@ static BOOL isPlistObject(id o) NSDate *started = [NSDateClass date]; unsigned long desired; unsigned long attributes; + static BOOL isLocked = NO; + BOOL wasLocked; [_lock lock]; - if (_fileLock != nil) + wasLocked = isLocked; + if (isLocked == NO && _fileLock != nil) { while ([_fileLock tryLock] == NO) { @@ -1364,6 +1367,7 @@ static BOOL isPlistObject(id o) } RELEASE(arp); } + isLocked = YES; } /* @@ -1403,7 +1407,11 @@ static BOOL isPlistObject(id o) } if (wantRead == NO) { - [_fileLock unlock]; + if (wasLocked == NO) + { + [_fileLock unlock]; + isLocked = NO; + } [_lock unlock]; return YES; } @@ -1431,7 +1439,11 @@ static BOOL isPlistObject(id o) if (newDict == nil) { NSLog(@"Unable to load defaults from '%@'", _defaultsDatabase); - [_fileLock unlock]; + if (wasLocked == NO) + { + [_fileLock unlock]; + isLocked = NO; + } [_lock unlock]; return NO; } @@ -1488,7 +1500,11 @@ static BOOL isPlistObject(id o) { if (![_persDomains writeToFile: _defaultsDatabase atomically: YES]) { - [_fileLock unlock]; + if (wasLocked == NO) + { + [_fileLock unlock]; + isLocked = NO; + } [_lock unlock]; return NO; } @@ -1513,7 +1529,11 @@ static BOOL isPlistObject(id o) } } - [_fileLock unlock]; + if (wasLocked == NO) + { + [_fileLock unlock]; + isLocked = NO; + } [_lock unlock]; return YES; }