Skip to content

Commit

Permalink
code formatting cleanup
Browse files Browse the repository at this point in the history
  • Loading branch information
stevedekorte committed Mar 1, 2020
1 parent 8b3d5ca commit 74ebbf1
Show file tree
Hide file tree
Showing 19 changed files with 40 additions and 99 deletions.
1 change: 0 additions & 1 deletion ActorKit/ActorKit.h
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,6 @@
// ActorKit.h
// ActorKit
//
// Created by Steve Dekorte on 20110830.
// Copyright 2011 Steve Dekorte. BSD licensed.
//

Expand Down
2 changes: 0 additions & 2 deletions ActorKit/ActorProxy.h
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,6 @@
// NSObject+Actor.h
// ActorKit
//
// Created by Steve Dekorte on 20110831.
// Copyright 2011 Steve Dekorte. BSD licensed.
//

Expand All @@ -13,7 +12,6 @@
@interface ActorProxy : NSProxy
{
// using the "actor" prefix to avoid name conflict with proxied object

id actorTarget;
Mutex *actorMutex;
FutureProxy *firstFuture;
Expand Down
34 changes: 10 additions & 24 deletions ActorKit/ActorProxy.m
Original file line number Diff line number Diff line change
Expand Up @@ -33,18 +33,15 @@ - (NSThread *)actorThreadCreateOrResumeIfNeeded
{
NSThread *thread = [self actorThread];

if(!thread)
{
if (!thread) {
[self setActorMutex:[[[Mutex alloc] init] autorelease]];
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
{
} else {
[actorMutex resumeAnyWaitingThreads];
}

Expand All @@ -56,8 +53,7 @@ - (void)dealloc
// threads retain the Future's they are waiting on, which retains the actor
// so dealloc should only occur when it's safe of dependencies

if([self actorThread])
{
if ([self actorThread]) {
[[self actorThread] cancel];
}

Expand All @@ -77,12 +73,9 @@ - (FutureProxy *)futurePerformInvocation:(NSInvocation *)anInvocation
[future setFutureInvocation:anInvocation];
[anInvocation retainArguments];

if([self firstFuture])
{
if ([self firstFuture]) {
[[self firstFuture] futureAppend:future];
}
else
{
} else {
[self setFirstFuture:future];
}

Expand All @@ -93,8 +86,7 @@ - (FutureProxy *)futurePerformInvocation:(NSInvocation *)anInvocation
willPauseCaller = (actorQueueLimit && actorQueueLimit == actorQueueSize);
[lock unlock];

if(willPauseCaller)
{
if (willPauseCaller) {
[future pauseThreadOnQueueLimitMutex];
}

Expand All @@ -105,17 +97,14 @@ - (void)actorRunLoop:sender
{
NSLock *lock = [[self actorThread] lock];

if([NSThread currentThread] != [self actorThread])
{
if ([NSThread currentThread] != [self actorThread]) {
[NSException raise:@"Actor" format:@"attempt to start actor loop from another thread"];
}

while(![[NSThread currentThread] isCancelled])
{
while(![[NSThread currentThread] isCancelled]) {
NSAutoreleasePool *pool = [[NSAutoreleasePool alloc] init];

while([self firstFuture])
{
while([self firstFuture]) {
FutureProxy *f = [self firstFuture];
[f futureSend]; // exceptions are caught within the futureSend method
[lock lock];
Expand All @@ -142,8 +131,7 @@ - (BOOL)respondsToSelector:(SEL)aSelector

- (void)forwardInvocation:(NSInvocation *)anInvocation
{
if([[anInvocation methodSignature] methodReturnType][0] != '@')
{
if ([[anInvocation methodSignature] methodReturnType][0] != '@') {
NSString *msg = [NSString stringWithFormat:@"sent '%@' but only methods that return objects are supported",
NSStringFromSelector([anInvocation selector])];
NSLog(@"ActorProxy ERROR: %@", msg);
Expand Down Expand Up @@ -189,6 +177,4 @@ - (void)resumeThreadWithReturnObject:(id)returnValue
[self resumeThread];
}



@end
4 changes: 0 additions & 4 deletions ActorKit/BatchProxy.h
Original file line number Diff line number Diff line change
Expand Up @@ -2,16 +2,13 @@
// NSObject+Actor.h
// ActorKit
//
// Created by Steve Dekorte on 20110831.
// Copyright 2011 Steve Dekorte. BSD licensed.
//

@interface BatchProxy : NSProxy
{
// using the "batch" prefix to avoid name conflict with proxied object

id batchTarget;

}

// private
Expand All @@ -20,5 +17,4 @@

- (void)setProxyTarget:anObject;


@end
6 changes: 2 additions & 4 deletions ActorKit/BatchProxy.m
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,6 @@
// NSObject+Actor.m
// ActorKit
//
// Created by Steve Dekorte on 20110831.
// Copyright 2011 Steve Dekorte. BSD licensed.
//

Expand Down Expand Up @@ -44,7 +43,7 @@ - (void)forwardInvocation:(NSInvocation *)theInvocation
{
__block NSInvocation *anInvocation = theInvocation;

if([[anInvocation methodSignature] methodReturnType][0] != '@')
if ([[anInvocation methodSignature] methodReturnType][0] != '@')
{
NSString *msg = [NSString stringWithFormat:@"sent '%@' but only methods that return objects are supported",
NSStringFromSelector([anInvocation selector])];
Expand Down Expand Up @@ -87,8 +86,7 @@ - (void)forwardInvocation:(NSInvocation *)theInvocation

- (NSMethodSignature *)methodSignatureForSelector:(SEL)aSelector
{
if([batchTarget count])
{
if ([batchTarget count]) {
id firstObject = [batchTarget objectAtIndex:0];
NSMethodSignature *sig = [firstObject methodSignatureForSelector:aSelector];
return sig;
Expand Down
1 change: 0 additions & 1 deletion ActorKit/FutureProxy.h
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,6 @@
// Future.h
// ActorKit
//
// Created by Steve Dekorte on 20110830.
// Copyright 2011 Steve Dekorte. BSD licensed.

#import "Mutex.h"
Expand Down
36 changes: 11 additions & 25 deletions ActorKit/FutureProxy.m
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,6 @@
// Future.m
// ActorKit
//
// Created by Steve Dekorte on 20110830.
// Copyright 2011 Steve Dekorte. BSD licensed.
//

Expand Down Expand Up @@ -51,12 +50,9 @@ - (void)dealloc

- (void)futureAppend:(FutureProxy *)aFuture
{
if(nextFuture)
{
if (nextFuture) {
[nextFuture futureAppend:aFuture];
}
else
{
} else {
[self setNextFuture:aFuture];
}
}
Expand All @@ -77,23 +73,19 @@ - (void)futureSend
{
[futureQueueLimitMutex resumeAnyWaitingThreads];

@try
{
@try {
//[self futureShowSend];
[futureInvocation invokeWithTarget:[futureActor actorTarget]];

id r;
[futureInvocation getReturnValue:(void *)&r];
[self setFutureResult:r];
}
@catch (NSException *e)
{
} @catch (NSException *e) {
[self setFutureException:e];
[self setFutureResult:nil];
}

for(NSThread *waitingThread in futureWaitingThreads)
{
for (NSThread *waitingThread in futureWaitingThreads) {
[waitingThread setWaitingOnFuture:nil];
}

Expand All @@ -103,8 +95,7 @@ - (void)futureSend

- (void)setFutureResult:(id)anObject
{
if(done)
{
if (done) {
return;
}

Expand All @@ -117,10 +108,8 @@ - (BOOL)isWaitingOnCurrentThread
{
// the recursion should avoid loop since the deadlock detection prevents loops

for(NSThread *waitingThread in futureWaitingThreads)
{
if([[waitingThread waitingOnFuture] isWaitingOnCurrentThread])
{
for (NSThread *waitingThread in futureWaitingThreads) {
if ([[waitingThread waitingOnFuture] isWaitingOnCurrentThread]) {
return YES;
}
}
Expand All @@ -130,8 +119,7 @@ - (BOOL)isWaitingOnCurrentThread

- (void)futurePassExceptionIfNeeded
{
if(futureException)
{
if (futureException) {
// guessing we have to wrap the exception so the stack info of original will be available
NSMutableDictionary *info = [NSMutableDictionary dictionary];
[info setObject:futureException forKey:@"exception"];
Expand All @@ -146,16 +134,14 @@ - (void)futurePassExceptionIfNeeded

- (void)futureRaiseExceptionIfDeadlock
{
if([self isWaitingOnCurrentThread])
{
if ([self isWaitingOnCurrentThread]) {
[NSException raise:@"Future" format:@"waiting for result on this coroutine would cause a deadlock"];
}
}

- futureResult
{
if(done)
{
if (done) {
[self futurePassExceptionIfNeeded];
return futureValue;
}
Expand Down
4 changes: 1 addition & 3 deletions ActorKit/Mutex.h
Original file line number Diff line number Diff line change
Expand Up @@ -2,10 +2,8 @@
// Mutex.h
// ActorKit
//
// Created by Steve Dekorte on 20110830.
// Copyright 2011 Steve Dekorte. BSD licensed.


//

@interface Mutex : NSObject
{
Expand Down
7 changes: 2 additions & 5 deletions ActorKit/Mutex.m
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,6 @@
// Mutex.m
// ActorKit
//
// Created by Steve Dekorte on 20110830.
// Copyright 2011 Steve Dekorte. BSD licensed.
//

Expand Down Expand Up @@ -47,8 +46,7 @@ - (void)pauseThread // have do be carefull about pauses and resumes mixing...
pthread_mutex_lock(&mutex);
isPaused = YES;

while (isPaused)
{
while (isPaused) {
pthread_cond_wait(&condition, &mutex);
}

Expand All @@ -57,8 +55,7 @@ - (void)pauseThread // have do be carefull about pauses and resumes mixing...

- (void)resumeAnyWaitingThreads
{
if(isPaused)
{
if (isPaused) {
pthread_mutex_lock(&mutex);
isPaused = NO;
pthread_cond_broadcast(&condition);
Expand Down
3 changes: 2 additions & 1 deletion ActorKit/NSArray+Actor.h
Original file line number Diff line number Diff line change
Expand Up @@ -2,13 +2,14 @@
// NSObject+Actor.h
// ActorKit
//
// Created by Steve Dekorte on 20110831.
// Copyright 2011 Steve Dekorte. BSD licensed.
//

#import <Foundation/Foundation.h>
#import "BatchProxy.h"

@interface NSArray (NSArray_Actor)

- asBatch;

@end
1 change: 0 additions & 1 deletion ActorKit/NSArray+Actor.m
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,6 @@
// NSObject+Actor.m
// ActorKit
//
// Created by Steve Dekorte on 20110831.
// Copyright 2011 Steve Dekorte. BSD licensed.
//

Expand Down
4 changes: 2 additions & 2 deletions ActorKit/NSInvocation+Copy.h
Original file line number Diff line number Diff line change
Expand Up @@ -2,11 +2,11 @@
// NSObject+Actor.h
// ActorKit
//
// Created by Steve Dekorte on 20110831.
// Copyright 2011 Steve Dekorte. BSD licensed.
//


@interface NSInvocation (NSInvocation_Copy)

- (id)copy;

@end
5 changes: 1 addition & 4 deletions ActorKit/NSInvocation+Copy.m
Original file line number Diff line number Diff line change
Expand Up @@ -2,22 +2,19 @@
// NSObject+Actor.m
// ActorKit
//
// Created by Steve Dekorte on 20110831.
// Copyright 2011 Steve Dekorte. BSD licensed.
//

#import "NSInvocation+Copy.h"


@implementation NSInvocation (NSInvocation_Copy)

- (id)copy
{
NSInvocation *copy = [NSInvocation invocationWithMethodSignature:[self methodSignature]];
NSUInteger argCount = [[self methodSignature] numberOfArguments];

for (int i = 0; i < argCount; i++)
{
for (int i = 0; i < argCount; i++) {
char buffer[sizeof(intmax_t)];
[self getArgument:(void *)&buffer atIndex:i];
[copy setArgument:(void *)&buffer atIndex:i];
Expand Down
1 change: 0 additions & 1 deletion ActorKit/NSObject+Actor.h
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,6 @@
// NSObject+Actor.h
// ActorKit
//
// Created by Steve Dekorte on 20110831.
// Copyright 2011 Steve Dekorte. BSD licensed.
//

Expand Down
Loading

0 comments on commit 74ebbf1

Please sign in to comment.