Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with HTTPS or Subversion.

Download ZIP

Loading…

Attempt to detect circular dependencies in operations #69

Closed
wants to merge 1 commit into from

2 participants

@amrox
Collaborator

No description provided.

@JaviSoto JaviSoto commented on the diff
Zinc/ZincOperation.m
@@ -58,4 +59,10 @@ - (float) progress
return ZincProgressCalculate(self);
}
+- (void)addDependency:(NSOperation *)op
+{
+ NSAssert(![[op zinc_allDependencies] containsObject:self], @"attempt to add circular dependency");
@JaviSoto Collaborator

For what we know, this is probably going to crash in develop now, right?

@JaviSoto Collaborator

Maybe add self and op to the assert message?

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
@JaviSoto
Collaborator

maybe write a test for this?

@JaviSoto JaviSoto commented on the diff
Zinc/NSOperation+Zinc.m
((1 lines not shown))
+//
+// NSOperation+Zinc.m
+// Zinc-ObjC
+//
+// Created by Andy Mroczkowski on 3/28/13.
+// Copyright (c) 2013 MindSnacks. All rights reserved.
+//
+
+#import "NSOperation+Zinc.h"
+
+@implementation NSOperation (Zinc)
+
+- (NSArray*) zinc_allDependencies
+{
+ NSMutableArray *todo = [NSMutableArray arrayWithObject:self];
+ NSMutableSet *done = [NSMutableSet set];
@JaviSoto Collaborator

Maybe rename this to visitedOperations, helps understand the algorithm better.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
@JaviSoto JaviSoto commented on the diff
Zinc/NSOperation+Zinc.m
@@ -0,0 +1,38 @@
+//
+// NSOperation+Zinc.m
+// Zinc-ObjC
+//
+// Created by Andy Mroczkowski on 3/28/13.
+// Copyright (c) 2013 MindSnacks. All rights reserved.
+//
+
+#import "NSOperation+Zinc.h"
+
+@implementation NSOperation (Zinc)
+
+- (NSArray*) zinc_allDependencies
+{
+ NSMutableArray *todo = [NSMutableArray arrayWithObject:self];
@JaviSoto Collaborator

Rename this to pendingOperationsToVisit also makes it more clear.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
@amrox amrox closed this
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Commits on Mar 28, 2013
  1. @amrox
This page is out of date. Refresh to see the latest.
View
8 Zinc-ObjC.xcodeproj/project.pbxproj
@@ -143,6 +143,8 @@
B3E6EED01590191500628816 /* sphalerite@2x.jpg in Resources */ = {isa = PBXBuildFile; fileRef = B393432C1588144200C81A4F /* sphalerite@2x.jpg */; };
B3E743B815998B9F0098DB19 /* com.mindsnacks.demo1.cats.json in Resources */ = {isa = PBXBuildFile; fileRef = B3E743B615998B9F0098DB19 /* com.mindsnacks.demo1.cats.json */; };
B3E743B915998B9F0098DB19 /* com.mindsnacks.demo1.cats.tar in Resources */ = {isa = PBXBuildFile; fileRef = B3E743B715998B9F0098DB19 /* com.mindsnacks.demo1.cats.tar */; };
+ B3E7510D1705027E00D8A989 /* NSOperation+Zinc.h in Headers */ = {isa = PBXBuildFile; fileRef = B3E7510B1705027E00D8A989 /* NSOperation+Zinc.h */; };
+ B3E7510E1705027E00D8A989 /* NSOperation+Zinc.m in Sources */ = {isa = PBXBuildFile; fileRef = B3E7510C1705027E00D8A989 /* NSOperation+Zinc.m */; };
B3EACD8714BD4907004D90EC /* ZincGarbageCollectTask.m in Sources */ = {isa = PBXBuildFile; fileRef = B3EACD8514BD4906004D90EC /* ZincGarbageCollectTask.m */; };
B3F14A5E15BB840900F7E22E /* ZincTaskActions.m in Sources */ = {isa = PBXBuildFile; fileRef = B3F14A5C15BB840900F7E22E /* ZincTaskActions.m */; };
B3F8AF77148EFCDF00CB92B5 /* ZincRepo.m in Sources */ = {isa = PBXBuildFile; fileRef = B3F8AF75148EFCDF00CB92B5 /* ZincRepo.m */; };
@@ -367,6 +369,8 @@
B3E46B9D14C4C00400030349 /* ZincRepoIndexTests.m */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.objc; path = ZincRepoIndexTests.m; sourceTree = "<group>"; };
B3E743B615998B9F0098DB19 /* com.mindsnacks.demo1.cats.json */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = text.json; path = com.mindsnacks.demo1.cats.json; sourceTree = "<group>"; };
B3E743B715998B9F0098DB19 /* com.mindsnacks.demo1.cats.tar */ = {isa = PBXFileReference; lastKnownFileType = archive.tar; path = com.mindsnacks.demo1.cats.tar; sourceTree = "<group>"; };
+ B3E7510B1705027E00D8A989 /* NSOperation+Zinc.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = "NSOperation+Zinc.h"; sourceTree = "<group>"; };
+ B3E7510C1705027E00D8A989 /* NSOperation+Zinc.m */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.objc; path = "NSOperation+Zinc.m"; sourceTree = "<group>"; };
B3EACD8414BD4905004D90EC /* ZincGarbageCollectTask.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; lineEnding = 0; path = ZincGarbageCollectTask.h; sourceTree = "<group>"; xcLanguageSpecificationIdentifier = xcode.lang.objcpp; };
B3EACD8514BD4906004D90EC /* ZincGarbageCollectTask.m */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.objc; lineEnding = 0; path = ZincGarbageCollectTask.m; sourceTree = "<group>"; xcLanguageSpecificationIdentifier = xcode.lang.objc; };
B3F14A5B15BB840900F7E22E /* ZincTaskActions.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = ZincTaskActions.h; sourceTree = "<group>"; };
@@ -838,6 +842,8 @@
B32BE82115EEF92900E6EBFA /* NSError+Zinc.m */,
B37023B716FA47D3007603F3 /* ZincHTTPRequestOperation+ZincContextInfo.h */,
B37023B816FA47D3007603F3 /* ZincHTTPRequestOperation+ZincContextInfo.m */,
+ B3E7510B1705027E00D8A989 /* NSOperation+Zinc.h */,
+ B3E7510C1705027E00D8A989 /* NSOperation+Zinc.m */,
);
name = Categories;
sourceTree = "<group>";
@@ -917,6 +923,7 @@
B31DE3B516CCBACA004F88ED /* ZincUtils.h in Headers */,
B31DE3B616CCBACA004F88ED /* ZincOperation.h in Headers */,
B37023B916FA47D3007603F3 /* ZincHTTPRequestOperation+ZincContextInfo.h in Headers */,
+ B3E7510D1705027E00D8A989 /* NSOperation+Zinc.h in Headers */,
);
runOnlyForDeploymentPostprocessing = 0;
};
@@ -1166,6 +1173,7 @@
B32FC70516AE0A2100E3A2C2 /* ZincCompleteInitializationTask.m in Sources */,
B31DE38716CB0030004F88ED /* NSFileManager+ZincTar.m in Sources */,
B37023BA16FA47D3007603F3 /* ZincHTTPRequestOperation+ZincContextInfo.m in Sources */,
+ B3E7510E1705027E00D8A989 /* NSOperation+Zinc.m in Sources */,
);
runOnlyForDeploymentPostprocessing = 0;
};
View
19 Zinc/NSOperation+Zinc.h
@@ -0,0 +1,19 @@
+//
+// NSOperation+Zinc.h
+// Zinc-ObjC
+//
+// Created by Andy Mroczkowski on 3/28/13.
+// Copyright (c) 2013 MindSnacks. All rights reserved.
+//
+
+#import <Foundation/Foundation.h>
+
+@interface NSOperation (Zinc)
+
+
+/**
+ @discussion returns ALL dependencies of the operation, recursively.
+ */
+- (NSArray*) zinc_allDependencies;
+
+@end
View
38 Zinc/NSOperation+Zinc.m
@@ -0,0 +1,38 @@
+//
+// NSOperation+Zinc.m
+// Zinc-ObjC
+//
+// Created by Andy Mroczkowski on 3/28/13.
+// Copyright (c) 2013 MindSnacks. All rights reserved.
+//
+
+#import "NSOperation+Zinc.h"
+
+@implementation NSOperation (Zinc)
+
+- (NSArray*) zinc_allDependencies
+{
+ NSMutableArray *todo = [NSMutableArray arrayWithObject:self];
@JaviSoto Collaborator

Rename this to pendingOperationsToVisit also makes it more clear.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
+ NSMutableSet *done = [NSMutableSet set];
@JaviSoto Collaborator

Maybe rename this to visitedOperations, helps understand the algorithm better.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
+ NSMutableArray *allDeps = [NSMutableArray array];
+
+ while ([todo count] > 0) {
+
+ NSOperation *op = [todo lastObject];
+ [todo removeLastObject];
+ [done addObject:op];
+
+ NSArray* deps = [op dependencies];
+ for (id obj in deps) {
+ [allDeps addObject:obj];
+ if (![done containsObject:obj]) {
+ [todo addObject:obj];
+ }
+ }
+ }
+
+ return allDeps;
+}
+
+@end
+
View
7 Zinc/ZincOperation.m
@@ -7,6 +7,7 @@
//
#import "ZincOperation.h"
+#import "NSOperation+Zinc.h"
double const kZincOperationInitialDefaultThreadPriority = 0.5;
@@ -58,4 +59,10 @@ - (float) progress
return ZincProgressCalculate(self);
}
+- (void)addDependency:(NSOperation *)op
+{
+ NSAssert(![[op zinc_allDependencies] containsObject:self], @"attempt to add circular dependency");
@JaviSoto Collaborator

For what we know, this is probably going to crash in develop now, right?

@JaviSoto Collaborator

Maybe add self and op to the assert message?

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
+ [super addDependency:op];
+}
+
@end
Something went wrong with that request. Please try again.