mirror of
https://github.com/gnustep/libs-base.git
synced 2025-05-31 16:50:58 +00:00
make very easy to update if/when we hae non-fragile ivars.
git-svn-id: svn+ssh://svn.gna.org/svn/gnustep/libs/base/trunk@28397 72102866-910b-0410-8b05-ffd578937521
This commit is contained in:
parent
60bc083760
commit
f737606d59
1 changed files with 92 additions and 37 deletions
|
@ -29,38 +29,60 @@
|
||||||
#import <Foundation/NSEnumerator.h>
|
#import <Foundation/NSEnumerator.h>
|
||||||
#import <Foundation/NSException.h>
|
#import <Foundation/NSException.h>
|
||||||
|
|
||||||
|
@interface NSOperationInternal : NSObject
|
||||||
|
{
|
||||||
|
@public
|
||||||
|
NSOperationQueuePriority priority;
|
||||||
|
BOOL cancelled;
|
||||||
|
BOOL concurrent;
|
||||||
|
BOOL executing;
|
||||||
|
BOOL finished;
|
||||||
|
BOOL ready;
|
||||||
|
NSMutableArray *dependencies;
|
||||||
|
}
|
||||||
|
@end
|
||||||
|
|
||||||
|
@implementation NSOperationInternal
|
||||||
|
/* As long as this class does nothing but act as a container for ivars,
|
||||||
|
* we can easily remove it at a later date using a global substitution
|
||||||
|
* to replace all the code of the form 'internal->ivar' with 'ivar'.
|
||||||
|
*/
|
||||||
|
@end
|
||||||
|
|
||||||
|
|
||||||
@implementation NSOperation : NSObject
|
@implementation NSOperation : NSObject
|
||||||
// Initialization
|
|
||||||
|
#define internal ((NSOperationInternal*)_internal)
|
||||||
|
|
||||||
|
- (void) dealloc
|
||||||
|
{
|
||||||
|
if (_internal != nil)
|
||||||
|
{
|
||||||
|
RELEASE(internal->dependencies);
|
||||||
|
[_internal release];
|
||||||
|
}
|
||||||
|
[super dealloc];
|
||||||
|
}
|
||||||
|
|
||||||
- (id) init
|
- (id) init
|
||||||
{
|
{
|
||||||
if((self = [super init]) != nil)
|
if ((self = [super init]) != nil)
|
||||||
{
|
{
|
||||||
priority = NSOperationQueuePriorityNormal;
|
_internal = [NSOperationInternal new];
|
||||||
|
internal->priority = NSOperationQueuePriorityNormal;
|
||||||
cancelled = NO;
|
internal->dependencies = [[NSMutableArray alloc] initWithCapacity: 5];
|
||||||
concurrent = NO;
|
|
||||||
executing = NO;
|
|
||||||
finished = NO;
|
|
||||||
ready = NO;
|
|
||||||
|
|
||||||
dependencies = [[NSMutableArray alloc] initWithCapacity: 5];
|
|
||||||
}
|
}
|
||||||
return self;
|
return self;
|
||||||
}
|
}
|
||||||
|
|
||||||
- (void) dealloc
|
|
||||||
{
|
|
||||||
RELEASE(dependencies);
|
|
||||||
[super dealloc];
|
|
||||||
}
|
|
||||||
|
|
||||||
// Executing the operation
|
// Executing the operation
|
||||||
- (void) start
|
- (void) start
|
||||||
{
|
{
|
||||||
executing = YES;
|
internal->executing = YES;
|
||||||
finished = NO;
|
internal->finished = NO;
|
||||||
|
|
||||||
if([self isConcurrent])
|
if ([self isConcurrent])
|
||||||
{
|
{
|
||||||
[self main];
|
[self main];
|
||||||
}
|
}
|
||||||
|
@ -77,8 +99,8 @@
|
||||||
NS_ENDHANDLER;
|
NS_ENDHANDLER;
|
||||||
}
|
}
|
||||||
|
|
||||||
executing = NO;
|
internal->executing = NO;
|
||||||
finished = YES;
|
internal->finished = YES;
|
||||||
}
|
}
|
||||||
|
|
||||||
- (void) main;
|
- (void) main;
|
||||||
|
@ -122,39 +144,71 @@
|
||||||
// Managing dependencies
|
// Managing dependencies
|
||||||
- (void) addDependency: (NSOperation *)op
|
- (void) addDependency: (NSOperation *)op
|
||||||
{
|
{
|
||||||
[dependencies addObject: op];
|
[internal->dependencies addObject: op];
|
||||||
}
|
}
|
||||||
|
|
||||||
- (void) removeDependency: (NSOperation *)op
|
- (void) removeDependency: (NSOperation *)op
|
||||||
{
|
{
|
||||||
[dependencies removeObject: op];
|
[internal->dependencies removeObject: op];
|
||||||
}
|
}
|
||||||
|
|
||||||
- (NSArray *)dependencies
|
- (NSArray *)dependencies
|
||||||
{
|
{
|
||||||
return [[NSArray alloc] initWithArray: dependencies];
|
return [NSArray arrayWithArray: internal->dependencies];
|
||||||
}
|
}
|
||||||
|
|
||||||
// Prioritization
|
// Prioritization
|
||||||
- (NSOperationQueuePriority) queuePriority
|
- (NSOperationQueuePriority) queuePriority
|
||||||
{
|
{
|
||||||
return priority;
|
return internal->priority;
|
||||||
}
|
}
|
||||||
|
|
||||||
- (void) setQueuePriority: (NSOperationQueuePriority)pri
|
- (void) setQueuePriority: (NSOperationQueuePriority)pri
|
||||||
{
|
{
|
||||||
priority = pri;
|
internal->priority = pri;
|
||||||
}
|
}
|
||||||
@end
|
@end
|
||||||
|
|
||||||
|
|
||||||
|
@interface NSOperationQueueInternal : NSObject
|
||||||
|
{
|
||||||
|
@public
|
||||||
|
NSMutableArray *operations;
|
||||||
|
BOOL suspended;
|
||||||
|
NSInteger count;
|
||||||
|
}
|
||||||
|
@end
|
||||||
|
|
||||||
|
@implementation NSOperationQueueInternal : NSObject
|
||||||
|
/* As long as this class does nothing but act as a container for ivars,
|
||||||
|
* we can easily remove it at a later date using a global substitution
|
||||||
|
* to replace all the code of the form 'internal->ivar' with 'ivar'.
|
||||||
|
*/
|
||||||
|
@end
|
||||||
|
|
||||||
@implementation NSOperationQueue
|
@implementation NSOperationQueue
|
||||||
|
|
||||||
|
#undef internal
|
||||||
|
#define internal ((NSOperationQueueInternal*)_internal)
|
||||||
|
|
||||||
|
- (void) dealloc
|
||||||
|
{
|
||||||
|
if (_internal != nil)
|
||||||
|
{
|
||||||
|
[internal->operations release];
|
||||||
|
[_internal release];
|
||||||
|
}
|
||||||
|
[super dealloc];
|
||||||
|
}
|
||||||
|
|
||||||
- (id) init
|
- (id) init
|
||||||
{
|
{
|
||||||
if((self = [super init]) != nil)
|
if ((self = [super init]) != nil)
|
||||||
{
|
{
|
||||||
suspended = NO;
|
_internal = [NSOperationQueueInternal new];
|
||||||
count = NSOperationQueueDefaultMaxConcurrentOperationCount;
|
internal->suspended = NO;
|
||||||
|
internal->count = NSOperationQueueDefaultMaxConcurrentOperationCount;
|
||||||
|
internal->operations = [NSMutableArray new];
|
||||||
}
|
}
|
||||||
return self;
|
return self;
|
||||||
}
|
}
|
||||||
|
@ -162,40 +216,41 @@
|
||||||
// status
|
// status
|
||||||
- (BOOL) isSuspended
|
- (BOOL) isSuspended
|
||||||
{
|
{
|
||||||
return suspended;
|
return internal->suspended;
|
||||||
}
|
}
|
||||||
|
|
||||||
- (void) setSuspended: (BOOL)flag
|
- (void) setSuspended: (BOOL)flag
|
||||||
{
|
{
|
||||||
suspended = flag;
|
internal->suspended = flag;
|
||||||
}
|
}
|
||||||
|
|
||||||
- (NSInteger) maxConcurrentOperationCount
|
- (NSInteger) maxConcurrentOperationCount
|
||||||
{
|
{
|
||||||
return count;
|
return internal->count;
|
||||||
}
|
}
|
||||||
|
|
||||||
- (void) setMaxConcurrentOperationCount: (NSInteger)cnt
|
- (void) setMaxConcurrentOperationCount: (NSInteger)cnt
|
||||||
{
|
{
|
||||||
count = cnt;
|
internal->count = cnt;
|
||||||
}
|
}
|
||||||
|
|
||||||
// operations
|
// operations
|
||||||
- (void) addOperation: (NSOperation *) op
|
- (void) addOperation: (NSOperation *) op
|
||||||
{
|
{
|
||||||
[operations addObject: op];
|
[internal->operations addObject: op];
|
||||||
}
|
}
|
||||||
|
|
||||||
- (NSArray *) operations
|
- (NSArray *) operations
|
||||||
{
|
{
|
||||||
return [[NSArray alloc] initWithArray: operations];
|
return [NSArray arrayWithArray: internal->operations];
|
||||||
}
|
}
|
||||||
|
|
||||||
- (void) cancelAllOperations
|
- (void) cancelAllOperations
|
||||||
{
|
{
|
||||||
NSEnumerator *en = [operations objectEnumerator];
|
NSEnumerator *en = [internal->operations objectEnumerator];
|
||||||
id o = nil;
|
id o = nil;
|
||||||
while( (o = [en nextObject]) != nil )
|
|
||||||
|
while ((o = [en nextObject]) != nil )
|
||||||
{
|
{
|
||||||
[o cancel];
|
[o cancel];
|
||||||
}
|
}
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue