Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with
or
.
Download ZIP
Browse files

cleanup

  • Loading branch information...
commit 9ce3e60da14430bad75fc5ad96e5bf04700f385b 1 parent bc2dd95
@stevedekorte authored
View
13 ActorKit/ActorProxy.m
@@ -18,6 +18,7 @@ @implementation ActorProxy
- init
{
+ //self = [super init]; // NSProxy doesn't implement init
return self;
}
@@ -51,8 +52,6 @@ - (void)dealloc
[[self actorThread] cancel];
}
- [self setFirstFuture:nil];
- [self setActorThread:nil];
[super dealloc];
}
@@ -93,7 +92,7 @@ - (void)actorRunLoop:sender
while(![[NSThread currentThread] isCancelled])
{
- NSAutoreleasePool *pool = [[NSAutoreleasePool alloc] init]; // Top-level pool
+ NSAutoreleasePool *pool = [[NSAutoreleasePool alloc] init];
while([self firstFuture])
{
@@ -108,6 +107,10 @@ - (void)actorRunLoop:sender
[[self mutex] pauseThread];
}
+
+ // do these here so they aren't freed before the thread is done
+ [self setFirstFuture:nil];
+ [self setActorThread:nil];
}
- (BOOL)respondsToSelector:(SEL)aSelector
@@ -119,7 +122,9 @@ - (void)forwardInvocation:(NSInvocation *)anInvocation
{
if([[anInvocation methodSignature] methodReturnType][0] != '@')
{
- [NSException raise:@"ActorProxy" format:[NSString stringWithFormat:@"'%@' only methods that return objects are supported", NSStringFromSelector([anInvocation selector])]];
+ [NSException raise:@"ActorProxy" format:
+ [NSString stringWithFormat:@"sent '%@' but only methods that return objects are supported",
+ NSStringFromSelector([anInvocation selector])]];
}
FutureProxy *f = [self futurePerformInvocation:anInvocation];
View
10 ActorKit/FutureProxy.m
@@ -22,7 +22,7 @@ @implementation FutureProxy
- (id)init
{
- //self = [super init];
+ //self = [super init]; // NSProxy doesn't implement init
if (self)
{
@@ -69,9 +69,10 @@ - (void)futureSend
{
@try
{
- id r;
//[self futureShowSend];
[futureInvocation invokeWithTarget:[actor actorTarget]];
+
+ id r;
[futureInvocation getReturnValue:(void *)&r];
[self setFutureResult:r];
}
@@ -105,7 +106,7 @@ - (void)setFutureResult:(id)anObject
- (BOOL)isWaitingOnCurrentThread
{
- // thie recursion should avoid loop since the deadlock detection prevents loops
+ // the recursion should avoid loop since the deadlock detection prevents loops
for(NSThread *waitingThread in waitingThreads)
{
@@ -149,8 +150,7 @@ - (BOOL)isWaitingOnCurrentThread
- (void)forwardInvocation:(NSInvocation *)anInvocation
{
- id r = [self futureResult];
- [anInvocation invokeWithTarget:r];
+ [anInvocation invokeWithTarget:[self futureResult]];
}
- (NSMethodSignature *)methodSignatureForSelector:(SEL)aSelector
View
28 ActorKit/Mutex.m
@@ -37,45 +37,27 @@ - (void)dealloc
[super dealloc];
}
-/*
-- (void)lock
-{
- pthread_mutex_lock(&mutex);
-}
-
-- (void)unlock
-{
- pthread_mutex_unlock(&mutex);
-}
-
-- (BOOL)tryLock
-{
- return pthread_mutex_trylock(&mutex) == 0; // 0 means we got the lock
-}
-*/
-
- (BOOL)isPaused
{
return isPaused;
}
- (void)pauseThread
-{
- //printf("%p pauseThread\n", (void *)[NSThread currentThread]);
-
+{
isPaused = YES;
+
pthread_mutex_lock(&mutex);
+
while (isPaused)
{
pthread_cond_wait( &condition, &mutex);
}
+
pthread_mutex_unlock(&mutex);
}
- (void)resumeThread
-{
- //printf("%p resumeThread\n", (void *)[NSThread currentThread]);
-
+{
if(isPaused)
{
isPaused = NO;
View
3  README.txt
@@ -11,7 +11,6 @@ About:
Example:
- // look ma, no state machines or callbacks
// these spawn threads to and return immediately
NSData *future1 = [(NSURL *)[[NSURL URLWithString:@"http://yahoo.com"] asActor] fetch];
@@ -23,7 +22,7 @@ Example:
NSLog(@"request 2 returned %i bytes", (int)[future2 length]);
// We just did a coordinated interaction between three threads
- // by only adding two tokens.
+ // by only adding two tokens and with no state machines or callbacks
Notes:
Please sign in to comment.
Something went wrong with that request. Please try again.