Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
MAFuture: re-base future hierarchy on custom MAProxy class
git-svn-id: http://mikeash.com/svn/MAFuture@114 1ea6ab17-982b-0410-b0ab-91172c90a6e5
- Loading branch information
mikeash
committed
Feb 6, 2010
1 parent
f90e3a2
commit 1a4d87e
Showing
6 changed files
with
95 additions
and
20 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
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,17 @@ | ||
@interface MAProxy | ||
{ | ||
Class isa; | ||
int32_t _refcountMinusOne; | ||
} | ||
|
||
+ (id)alloc; | ||
|
||
- (void)dealloc; | ||
- (BOOL)isProxy; | ||
- (id)retain; | ||
- (void)release; | ||
- (id)autorelease; | ||
- (NSUInteger)retainCount; | ||
|
||
@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,56 @@ | ||
#import <Foundation/Foundation.h> | ||
#import <libkern/OSAtomic.h> | ||
|
||
#import "MAProxy.h" | ||
|
||
|
||
@implementation MAProxy | ||
|
||
+ (void)initialize | ||
{ | ||
// runtime requires an implementation | ||
} | ||
|
||
+ (id)alloc | ||
{ | ||
return NSAllocateObject(self, 0, NULL); | ||
} | ||
|
||
- (void)dealloc | ||
{ | ||
NSDeallocateObject(self); | ||
} | ||
|
||
- (void)finalize | ||
{ | ||
} | ||
|
||
- (BOOL)isProxy | ||
{ | ||
return YES; | ||
} | ||
|
||
- (id)retain | ||
{ | ||
OSAtomicIncrement32(&_refcountMinusOne); | ||
return self; | ||
} | ||
|
||
- (void)release | ||
{ | ||
if(OSAtomicDecrement32(&_refcountMinusOne) == -1) | ||
[self dealloc]; | ||
} | ||
|
||
- (id)autorelease | ||
{ | ||
[NSAutoreleasePool addObject: self]; | ||
return self; | ||
} | ||
|
||
- (NSUInteger)retainCount | ||
{ | ||
return _refcountMinusOne + 1; | ||
} | ||
|
||
@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