GC tidyups

git-svn-id: svn+ssh://svn.gna.org/svn/gnustep/libs/base/trunk@7509 72102866-910b-0410-8b05-ffd578937521
This commit is contained in:
richard 2000-09-14 08:48:05 +00:00
parent 2b652c7503
commit 6f6debd1e6
3 changed files with 79 additions and 63 deletions

View file

@ -1,3 +1,9 @@
2000-09-14 Richard Frith-Macdonald <rfm@gnu.org>
* Headers/gnustep/base/NSLock.h: conform to GCFinalization protocol.
* Source/NSLock.m: deallocate mutex in gcFinalize. Don't raise an
exception if mutex deallocation fails.
2000-09-13 Adam Fedor <fedor@gnu.org>
* Remove dependance on Source/Foundation link, additional MINGW ports.

View file

@ -48,7 +48,7 @@
* NSLock class
* Simplest lock for protecting critical sections of code
*/
@interface NSLock : NSObject <NSLocking>
@interface NSLock : NSObject <NSLocking, GCFinalization>
{
@private
objc_mutex_t _mutex;
@ -66,7 +66,7 @@
* NSConditionLock
* Allows locking and unlocking to be based upon a condition
*/
@interface NSConditionLock : NSObject <NSLocking>
@interface NSConditionLock : NSObject <NSLocking, GCFinalization>
{
@private
objc_condition_t _condition;
@ -112,7 +112,7 @@
* thread must also unlock it (n) times before another thread
* can acquire the lock.
*/
@interface NSRecursiveLock : NSObject <NSLocking>
@interface NSRecursiveLock : NSObject <NSLocking, GCFinalization>
{
@private
objc_mutex_t _mutex;

View file

@ -66,29 +66,35 @@ NSString *NSRecursiveLockException = @"NSRecursiveLockException";
// Designated initializer
- (id) init
{
[super init];
self = [super init];
if (self != nil)
{
// Allocate the mutex from the runtime
_mutex = objc_mutex_allocate();
if (!_mutex)
if (_mutex == 0)
{
RELEASE(self);
NSLog(@"Failed to allocate a mutex");
return nil;
}
}
return self;
}
- (void) dealloc
{
[self gcFinalize];
[super dealloc];
}
- (void) gcFinalize
{
// Ask the runtime to deallocate the mutex
// If there are outstanding locks then it will block
if (objc_mutex_deallocate(_mutex) == -1)
{
[NSException raise:NSLockException
format:@"invalid mutex"];
/* NOT REACHED */
NSWarnMLog(@"objc_mutex_deallocate() failed");
}
[super dealloc];
}
// Try to acquire the lock
@ -209,22 +215,23 @@ NSString *NSRecursiveLockException = @"NSRecursiveLockException";
}
- (void) dealloc
{
[self gcFinalize];
[super dealloc];
}
- (void) gcFinalize
{
// Ask the runtime to deallocate the mutex
// If there are outstanding locks then it will block
if (objc_condition_deallocate(_condition) == -1)
{
[NSException raise:NSConditionLockException
format:@"dealloc: invalid condition"];
/* NOT REACHED */
NSWarnMLog(@"objc_condition_deallocate() failed");
}
if (objc_mutex_deallocate(_mutex) == -1)
{
[NSException raise:NSConditionLockException
format:@"dealloc: invalid mutex"];
/* NOT REACHED */
NSWarnMLog(@"objc_mutex_deallocate() failed");
}
[super dealloc];
}
// Return the current condition of the lock
@ -465,16 +472,19 @@ NSString *NSRecursiveLockException = @"NSRecursiveLockException";
}
- (void) dealloc
{
[self gcFinalize];
[super dealloc];
}
- (void) gcFinalize
{
// Ask the runtime to deallocate the mutex
// If there are outstanding locks then it will block
if (objc_mutex_deallocate(_mutex) == -1)
{
[NSException raise:NSRecursiveLockException
format:@"dealloc: invalid mutex"];
/* NOT REACHED */
NSWarnMLog(@"objc_mutex_deallocate() failed");
}
[super dealloc];
}
// Try to acquire the lock