Permalink
Browse files

added ActorProxy methods for pause/resume for easy support of async c…

…allbacks within a thread
  • Loading branch information...
1 parent 30b24ea commit 8df73e10d9548de9c5a2b844cb63f569b73ac757 @stevedekorte committed Sep 10, 2012
View
BIN .DS_Store
Binary file not shown.
View
5 ActorKit.xcodeproj/project.pbxproj
@@ -201,6 +201,9 @@
/* Begin PBXProject section */
AABB5D8B140E0C220020BA06 /* Project object */ = {
isa = PBXProject;
+ attributes = {
+ LastUpgradeCheck = 0440;
+ };
buildConfigurationList = AABB5D8E140E0C220020BA06 /* Build configuration list for PBXProject "ActorKit" */;
compatibilityVersion = "Xcode 3.2";
developmentRegion = English;
@@ -310,6 +313,7 @@
AABB5DAB140E0C220020BA06 /* Debug */ = {
isa = XCBuildConfiguration;
buildSettings = {
+ COMBINE_HIDPI_IMAGES = YES;
DYLIB_COMPATIBILITY_VERSION = 1;
DYLIB_CURRENT_VERSION = 1;
FRAMEWORK_VERSION = A;
@@ -324,6 +328,7 @@
AABB5DAC140E0C220020BA06 /* Release */ = {
isa = XCBuildConfiguration;
buildSettings = {
+ COMBINE_HIDPI_IMAGES = YES;
DYLIB_COMPATIBILITY_VERSION = 1;
DYLIB_CURRENT_VERSION = 1;
FRAMEWORK_VERSION = A;
View
BIN ...xcodeproj/project.xcworkspace/xcuserdata/steve.xcuserdatad/UserInterfaceState.xcuserstate
Binary file not shown.
View
11 ActorKit.xcodeproj/xcuserdata/steve.xcuserdatad/xcschemes/ActorKit.xcscheme
@@ -1,5 +1,6 @@
<?xml version="1.0" encoding="UTF-8"?>
<Scheme
+ LastUpgradeVersion = "0440"
version = "1.3">
<BuildAction
parallelizeBuildables = "YES"
@@ -30,19 +31,23 @@
</Testables>
</TestAction>
<LaunchAction
- selectedDebuggerIdentifier = "Xcode.DebuggerFoundation.Debugger.GDB"
+ selectedDebuggerIdentifier = "Xcode.DebuggerFoundation.Debugger.LLDB"
selectedLauncherIdentifier = "Xcode.DebuggerFoundation.Launcher.GDB"
launchStyle = "0"
useCustomWorkingDirectory = "NO"
- buildConfiguration = "Debug">
+ buildConfiguration = "Debug"
+ ignoresPersistentStateOnLaunch = "NO"
+ debugDocumentVersioning = "YES"
+ allowLocationSimulation = "YES">
<AdditionalOptions>
</AdditionalOptions>
</LaunchAction>
<ProfileAction
shouldUseLaunchSchemeArgsEnv = "YES"
savedToolIdentifier = ""
useCustomWorkingDirectory = "NO"
- buildConfiguration = "Release">
+ buildConfiguration = "Release"
+ debugDocumentVersioning = "YES">
</ProfileAction>
<AnalyzeAction
buildConfiguration = "Debug">
View
6 ActorKit/ActorProxy.h
@@ -36,4 +36,10 @@
@property (assign, atomic) size_t actorQueueLimit;
++ (ActorProxy *)currentActorProxy;
+
+- (id)pauseThread; // returns with object passed to resumeThreadWithReturnObject:
+- (void)resumeThread;
+- (void)resumeThreadWithReturnObject:(id)returnValue;
+
@end
View
43 ActorKit/ActorProxy.m
@@ -7,7 +7,7 @@
//
#import "ActorProxy.h"
-
+#import "FutureProxy.h"
@implementation ActorProxy
@@ -39,6 +39,8 @@ - (NSThread *)actorThreadCreateOrResumeIfNeeded
thread = [[[NSThread alloc] initWithTarget:self selector:@selector(actorRunLoop:) object:nil] autorelease];
[self setActorThread:thread];
[thread setName:[NSString stringWithFormat:@"%@", [actorTarget className]]];
+
+ [[thread threadDictionary] setObject:self forKey:@"actorProxy"];
[thread start];
}
else
@@ -142,9 +144,10 @@ - (void)forwardInvocation:(NSInvocation *)anInvocation
{
if([[anInvocation methodSignature] methodReturnType][0] != '@')
{
- [NSException raise:@"ActorProxy" format:
- [NSString stringWithFormat:@"sent '%@' but only methods that return objects are supported",
- NSStringFromSelector([anInvocation selector])]];
+ NSString *msg = [NSString stringWithFormat:@"sent '%@' but only methods that return objects are supported",
+ NSStringFromSelector([anInvocation selector])];
+ NSLog(@"ActorProxy ERROR: %@", msg);
+ [NSException raise:@"ActorProxy" format:@"%@", msg];
}
FutureProxy *f = [self futurePerformInvocation:anInvocation];
@@ -156,4 +159,36 @@ - (NSMethodSignature *)methodSignatureForSelector:(SEL)aSelector
return [actorTarget methodSignatureForSelector:aSelector];
}
+// --- pausing and resuming ---
+//
+// for use from within an actor method executing in order to
+// pause actor thread while waiting on async ops or other callbacks
+
++ (ActorProxy *)currentActorProxy
+{
+ return [[[NSThread currentThread] threadDictionary] objectForKey:@"actorProxy"];
+}
+
+- (id)pauseThread
+{
+ [actorMutex pauseThread];
+ id returnValue = [[[NSThread currentThread] threadDictionary] objectForKey:@"returnValue"];
+ [[[NSThread currentThread] threadDictionary] removeObjectForKey:@"returnValue"];
+ return returnValue;
+}
+
+- (void)resumeThread
+{
+ [actorMutex resumeAnyWaitingThreads];
+}
+
+- (void)resumeThreadWithReturnObject:(id)returnValue
+{
+ // might move returnValue to ivar
+ [[[NSThread currentThread] threadDictionary] setObject:returnValue forKey:@"returnValue"];
+ [self resumeThread];
+}
+
+
+
@end
View
7 ActorKit/BatchProxy.m
@@ -46,9 +46,10 @@ - (void)forwardInvocation:(NSInvocation *)theInvocation
if([[anInvocation methodSignature] methodReturnType][0] != '@')
{
- [NSException raise:@"BatchProxy" format:
- [NSString stringWithFormat:@"sent '%@' but only methods that return objects are supported",
- NSStringFromSelector([anInvocation selector])]];
+ NSString *msg = [NSString stringWithFormat:@"sent '%@' but only methods that return objects are supported",
+ NSStringFromSelector([anInvocation selector])];
+ NSLog(@"BatchProxy ERROR: %@", msg);
+ [NSException raise:@"BatchProxy" format:@"%@", msg];
}
[anInvocation retain]; // uh, why?
View
2 ActorKit/FutureProxy.h
@@ -33,6 +33,8 @@
@property (retain, atomic) Mutex *futureLock;
@property (retain, atomic) Mutex *futureQueueLimitMutex;
+- (id)init;
+
- (void)futureAppend:(FutureProxy *)aFuture;
- (void)futureSend;
View
4 ActorKit/NSThread+Actor.m
@@ -44,9 +44,9 @@ - (void)setLock:(id)anObject
}
}
-- (Mutex *)lock
+- (NSLock *)lock
{
- Mutex *lock = [[self threadDictionary] objectForKey:@"lock"];
+ NSLock *lock = [[self threadDictionary] objectForKey:@"lock"];
if (lock == nil)
{

0 comments on commit 8df73e1

Please sign in to comment.