git-svn-id: svn+ssh://svn.gna.org/svn/gnustep/libs/base/trunk@7512 72102866-910b-0410-8b05-ffd578937521
This commit is contained in:
richard 2000-09-14 09:37:13 +00:00
parent 6f6debd1e6
commit 39810508b6

View file

@ -27,6 +27,7 @@
#include <base/preface.h> #include <base/preface.h>
#include <Foundation/NSLock.h> #include <Foundation/NSLock.h>
#include <Foundation/NSException.h> #include <Foundation/NSException.h>
#include <Foundation/NSDebug.h>
// Exceptions // Exceptions
@ -89,11 +90,14 @@ NSString *NSRecursiveLockException = @"NSRecursiveLockException";
- (void) gcFinalize - (void) gcFinalize
{ {
// Ask the runtime to deallocate the mutex if (_mutex != 0)
// If there are outstanding locks then it will block
if (objc_mutex_deallocate(_mutex) == -1)
{ {
NSWarnMLog(@"objc_mutex_deallocate() failed"); // Ask the runtime to deallocate the mutex
// If there are outstanding locks then it will block
if (objc_mutex_deallocate(_mutex) == -1)
{
NSWarnMLog(@"objc_mutex_deallocate() failed");
}
} }
} }
@ -172,7 +176,7 @@ NSString *NSRecursiveLockException = @"NSRecursiveLockException";
if (objc_mutex_unlock(_mutex) == -1) if (objc_mutex_unlock(_mutex) == -1)
{ {
[NSException raise: NSLockException [NSException raise: NSLockException
format: @"unlock: failed to unlock mutex"]; format: @"unlock: failed to unlock mutex"];
/* NOT REACHED */ /* NOT REACHED */
} }
} }
@ -194,22 +198,26 @@ NSString *NSRecursiveLockException = @"NSRecursiveLockException";
// Initialize lock with condition // Initialize lock with condition
- (id) initWithCondition: (int)value - (id) initWithCondition: (int)value
{ {
[super init]; self = [super init];
if (self != nil)
_condition_value = value; {
_condition_value = value;
// Allocate the mutex from the runtime // Allocate the mutex from the runtime
_condition = objc_condition_allocate (); _condition = objc_condition_allocate ();
if (!_condition) if (_condition == 0)
{ {
NSLog(@"Failed to allocate a condition"); NSLog(@"Failed to allocate a condition");
return nil; RELEASE(self);
} return nil;
_mutex = objc_mutex_allocate (); }
if (!_mutex) _mutex = objc_mutex_allocate ();
{ if (_mutex == 0)
NSLog(@"Failed to allocate a mutex"); {
return nil; NSLog(@"Failed to allocate a mutex");
RELEASE(self);
return nil;
}
} }
return self; return self;
} }
@ -222,15 +230,22 @@ NSString *NSRecursiveLockException = @"NSRecursiveLockException";
- (void) gcFinalize - (void) gcFinalize
{ {
// Ask the runtime to deallocate the mutex if (_condition != 0)
// If there are outstanding locks then it will block
if (objc_condition_deallocate(_condition) == -1)
{ {
NSWarnMLog(@"objc_condition_deallocate() failed"); // Ask the runtime to deallocate the condition
if (objc_condition_deallocate(_condition) == -1)
{
NSWarnMLog(@"objc_condition_deallocate() failed");
}
} }
if (objc_mutex_deallocate(_mutex) == -1) if (_mutex != 0)
{ {
NSWarnMLog(@"objc_mutex_deallocate() failed"); // Ask the runtime to deallocate the mutex
// If there are outstanding locks then it will block
if (objc_mutex_deallocate(_mutex) == -1)
{
NSWarnMLog(@"objc_mutex_deallocate() failed");
}
} }
} }
@ -459,14 +474,17 @@ NSString *NSRecursiveLockException = @"NSRecursiveLockException";
// Designated initializer // Designated initializer
- (id) init - (id) init
{ {
[super init]; self = [super init];
if (self != nil)
// Allocate the mutex from the runtime
_mutex = objc_mutex_allocate();
if (!_mutex)
{ {
NSLog(@"Failed to allocate a mutex"); // Allocate the mutex from the runtime
return nil; _mutex = objc_mutex_allocate();
if (_mutex == 0)
{
NSLog(@"Failed to allocate a mutex");
RELEASE(self);
return nil;
}
} }
return self; return self;
} }
@ -479,11 +497,14 @@ NSString *NSRecursiveLockException = @"NSRecursiveLockException";
- (void) gcFinalize - (void) gcFinalize
{ {
// Ask the runtime to deallocate the mutex if (_mutex != 0)
// If there are outstanding locks then it will block
if (objc_mutex_deallocate(_mutex) == -1)
{ {
NSWarnMLog(@"objc_mutex_deallocate() failed"); // Ask the runtime to deallocate the mutex
// If there are outstanding locks then it will block
if (objc_mutex_deallocate(_mutex) == -1)
{
NSWarnMLog(@"objc_mutex_deallocate() failed");
}
} }
} }