Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
1 parent
0da6c31
commit 155e24a
Showing
3 changed files
with
79 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -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 |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -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 |