Tiny code simplification.

git-svn-id: svn+ssh://svn.gna.org/svn/gnustep/libs/base/trunk@39905 72102866-910b-0410-8b05-ffd578937521
This commit is contained in:
Richard Frith-MacDonald 2016-06-22 13:21:04 +00:00
parent 8b4923c76e
commit 8fd0387e36
2 changed files with 9 additions and 9 deletions

View file

@ -80,6 +80,10 @@ static NSFileManager *mgr = nil;
{
NSDictionary *attributes;
if (nil != _lockTime)
{
NSLog(@"Breaking our own distributed lock %@", _lockPath);
}
DESTROY(_lockTime);
attributes = [mgr fileAttributesAtPath: _lockPath traverseLink: YES];
if (attributes != nil)

View file

@ -2332,19 +2332,15 @@ static BOOL isLocked = NO;
while ([_fileLock tryLock] == NO)
{
CREATE_AUTORELEASE_POOL(arp);
NSDate *when;
NSDate *lockDate;
lockDate = [_fileLock lockDate];
when = [NSDateClass dateWithTimeIntervalSinceNow: 0.1];
/*
* In case we have tried and failed to break the lock,
* we give up after a while ... 66 seconds should give
* us three lock breaks if we do them at 20 second
* intervals.
*/
if ([when timeIntervalSinceDate: started] > 66.0)
if ([started timeIntervalSinceNow] < -66.0)
{
fprintf(stderr, "Failed to lock user defaults database"
" even after breaking old locks!\n");
@ -2356,16 +2352,16 @@ static BOOL isLocked = NO;
* wait a little anyway ... so that in the case of a locking
* problem we do an idle wait rather than a busy one.
*/
if (lockDate != nil
&& [when timeIntervalSinceDate: lockDate] > 20.0)
if ((lockDate = [_fileLock lockDate]) != nil
&& [lockDate timeIntervalSinceNow] < -20.0)
{
NSLog(@"NSUserdefaults file lock at %@ is dated %@ ... break",
NSLog(@"NSUserDefaults file lock at %@ is dated %@ ... break",
_fileLock, lockDate);
[_fileLock breakLock];
}
else
{
[NSThread sleepUntilDate: when];
[NSThread sleepForTimeInterval: 0.1];
}
RELEASE(arp);
}