Don't obtain locks unnecessarily

git-svn-id: svn+ssh://svn.gna.org/svn/gnustep/libs/base/trunk@18071 72102866-910b-0410-8b05-ffd578937521
This commit is contained in:
CaS 2003-11-10 06:40:24 +00:00
parent afc5f3d31e
commit c3bccbefe1
2 changed files with 49 additions and 42 deletions

View file

@ -1,3 +1,9 @@
2003-11-10 Richard Frith-Macdonald <rfm@gnu.org>
* Source/NSUserDefaults.m: Only obtain distributed lock for reading
or writing defaults ... not needed just to check the modification
date. Avoids unnecessary filesystem writes.
2003-11-09 Frederic De Jaeger <dejaeger@free.fr>
* Source/GSFileHandle.m ([GSFileHandle

View file

@ -1328,6 +1328,48 @@ static BOOL isPlistObject(id o)
[_lock lock];
/*
* If we haven't changed anything, we only need to synchronise if
* the on-disk database has been changed by someone else.
*/
attr = [mgr fileAttributesAtPath: _defaultsDatabase
traverseLink: YES];
if (_changedDomains == nil)
{
BOOL wantRead = NO;
if (_lastSync == nil)
{
wantRead = YES;
}
else
{
if (attr == nil)
{
wantRead = YES;
}
else
{
NSDate *mod;
/*
* If the database was modified since the last synchronisation
* we need to read it.
*/
mod = [attr objectForKey: NSFileModificationDate];
if (mod != nil && [_lastSync laterDate: mod] != _lastSync)
{
wantRead = YES;
}
}
}
if (wantRead == NO)
{
[_lock unlock];
return YES;
}
}
wasLocked = isLocked;
if (isLocked == NO && _fileLock != nil)
{
@ -1373,51 +1415,10 @@ static BOOL isPlistObject(id o)
}
/*
* If we haven't changed anything, we only need to synchronise if
* the on-disk database has been changed by someone else.
* Re-fetch database attributes in cased they changed while obtaining lock.
*/
attr = [mgr fileAttributesAtPath: _defaultsDatabase
traverseLink: YES];
if (_changedDomains == nil)
{
BOOL wantRead = NO;
if (_lastSync == nil)
{
wantRead = YES;
}
else
{
if (attr == nil)
{
wantRead = YES;
}
else
{
NSDate *mod;
/*
* If the database was modified since the last synchronisation
* we need to read it.
*/
mod = [attr objectForKey: NSFileModificationDate];
if (mod != nil && [_lastSync laterDate: mod] != _lastSync)
{
wantRead = YES;
}
}
}
if (wantRead == NO)
{
if (wasLocked == NO)
{
[_fileLock unlock];
isLocked = NO;
}
[_lock unlock];
return YES;
}
}
DESTROY(_dictionaryRep);