Skip to content

Commit

Permalink
forgot to add NSThread+Actor
Browse files Browse the repository at this point in the history
  • Loading branch information
stevedekorte committed Sep 13, 2011
1 parent 0da6c31 commit 155e24a
Show file tree
Hide file tree
Showing 3 changed files with 79 additions and 0 deletions.
1 change: 1 addition & 0 deletions ActorKit/NSObject+Actor.m
Expand Up @@ -33,6 +33,7 @@ - (Future *)firstFuture
return (Future *)objc_getAssociatedObject(self, "firstFuture");
}


- (void)setActorThread:(NSThread *)aThread
{
objc_setAssociatedObject(self, "actorThread", aThread, OBJC_ASSOCIATION_RETAIN_NONATOMIC);
Expand Down
18 changes: 18 additions & 0 deletions ActorKit/NSThread+Actor.h
@@ -0,0 +1,18 @@
//
// NSObject+Actor.h
// ActorKit
//
// Created by Steve Dekorte on 20110831.
// Copyright 2011 Steve Dekorte. BSD licensed.
//

#import <Foundation/Foundation.h>

@interface NSThread (NSThread_Actor)

- (void)setWaitingOnFuture:(id)aFuture;
- waitingOnFuture;

- (NSLock *)lock;

@end
60 changes: 60 additions & 0 deletions ActorKit/NSThread+Actor.m
@@ -0,0 +1,60 @@
//
// NSObject+Actor.m
// ActorKit
//
// Created by Steve Dekorte on 20110831.
// Copyright 2011 Steve Dekorte. BSD licensed.
//

#import "NSThread+Actor.h"
#import "Mutex.h"

@implementation NSThread (NSThread_Actor)

// future

- (void)setWaitingOnFuture:(id)anObject
{
if(anObject == nil)
{
[[self threadDictionary] removeObjectForKey:@"waitingOnFuture"];
}
else
{
[[self threadDictionary] setObject:anObject forKey:@"waitingOnFuture"];
}
}

- waitingOnFuture
{
return [[self threadDictionary] objectForKey:@"waitingOnFuture"];
}

// lock

- (void)setLock:(id)anObject
{
if(anObject == nil)
{
[[self threadDictionary] removeObjectForKey:@"lock"];
}
else
{
[[self threadDictionary] setObject:anObject forKey:@"lock"];
}
}

- (Mutex *)lock
{
Mutex *lock = [[self threadDictionary] objectForKey:@"lock"];

if (!lock)
{
lock = [[[NSLock alloc] init] autorelease];
[self setLock:lock];
}

return lock;
}

@end

0 comments on commit 155e24a

Please sign in to comment.