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> 2000-09-13 Adam Fedor <fedor@gnu.org>
* Remove dependance on Source/Foundation link, additional MINGW ports. * Remove dependance on Source/Foundation link, additional MINGW ports.

View file

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

View file

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