diff options
author | Jay Freeman (saurik) <saurik@saurik.com> | 2011-03-01 08:59:25 -0800 |
---|---|---|
committer | Jay Freeman (saurik) <saurik@saurik.com> | 2011-03-07 02:41:33 -0800 |
commit | 28b8b6877651f80fbee2a8c4cd82c455bd7d2143 (patch) | |
tree | 6fe08c9eef98016e28ad05b11265e6ec0efc76b6 /MobileCydia.mm | |
parent | 09e89a8a6d75e0e9913c419049012cef6e9da785 (diff) |
Separate out Menes/NSObject-MenesYieldToSelector.*.
Diffstat (limited to 'MobileCydia.mm')
-rw-r--r-- | MobileCydia.mm | 69 |
1 files changed, 2 insertions, 67 deletions
diff --git a/MobileCydia.mm b/MobileCydia.mm index 048d3f5..b29fd99 100644 --- a/MobileCydia.mm +++ b/MobileCydia.mm @@ -125,6 +125,8 @@ extern "C" { #include "CyteKit/PerlCompatibleRegEx.hpp" #include "CyteKit/WebScriptObject-Cyte.h" +#include "Menes/Menes.h" + #include "SDURLCache/SDURLCache.h" #include <CydiaSubstrate/CydiaSubstrate.h> @@ -269,73 +271,6 @@ static _finline void UpdateExternalStatus(uint64_t newStatus) { notify_post("com.saurik.Cydia.status"); } -/* [NSObject yieldToSelector:(withObject:)] {{{*/ -@interface NSObject (Cydia) -- (id) yieldToSelector:(SEL)selector withObject:(id)object; -- (id) yieldToSelector:(SEL)selector; -@end - -@implementation NSObject (Cydia) - -- (void) doNothing { -} - -- (void) _yieldToContext:(NSMutableArray *)context { _pooled - SEL selector(reinterpret_cast<SEL>([[context objectAtIndex:0] pointerValue])); - id object([[context objectAtIndex:1] nonretainedObjectValue]); - volatile bool &stopped(*reinterpret_cast<bool *>([[context objectAtIndex:2] pointerValue])); - - /* XXX: deal with exceptions */ - id value([self performSelector:selector withObject:object]); - - NSMethodSignature *signature([self methodSignatureForSelector:selector]); - [context removeAllObjects]; - if ([signature methodReturnLength] != 0 && value != nil) - [context addObject:value]; - - stopped = true; - - [self - performSelectorOnMainThread:@selector(doNothing) - withObject:nil - waitUntilDone:NO - ]; -} - -- (id) yieldToSelector:(SEL)selector withObject:(id)object { - volatile bool stopped(false); - - NSMutableArray *context([NSMutableArray arrayWithObjects: - [NSValue valueWithPointer:selector], - [NSValue valueWithNonretainedObject:object], - [NSValue valueWithPointer:const_cast<bool *>(&stopped)], - nil]); - - NSThread *thread([[[NSThread alloc] - initWithTarget:self - selector:@selector(_yieldToContext:) - object:context - ] autorelease]); - - [thread start]; - - NSRunLoop *loop([NSRunLoop currentRunLoop]); - NSDate *future([NSDate distantFuture]); - NSString *mode([loop currentMode] ?: NSDefaultRunLoopMode); - -_trace(); - while (!stopped && [loop runMode:mode beforeDate:future]); -_trace(); - - return [context count] == 0 ? nil : [context objectAtIndex:0]; -} - -- (id) yieldToSelector:(SEL)selector { - return [self yieldToSelector:selector withObject:nil]; -} - -@end -/* }}} */ /* Cydia Alert View {{{ */ @interface CYAlertView : UIAlertView { |