Index: src/OFObject.h ================================================================== --- src/OFObject.h +++ src/OFObject.h @@ -679,10 +679,48 @@ onThread: (OFThread*)thread withObject: (id)object1 withObject: (id)object2 waitUntilDone: (BOOL)waitUntilDone; +/** + * \brief Performs the specified selector on the main thread. + * + * \param selector The selector to perform + * \param waitUntilDone Whether to wait until the perform finished + */ +- (void)performSelectorOnMainThread: (SEL)selector + waitUntilDone: (BOOL)waitUntilDone; + +/** + * \brief Performs the specified selector on the main thread with the specified + * object. + * + * \param selector The selector to perform + * \param object The object that is passed to the method specified by the + * selector + * \param waitUntilDone Whether to wait until the perform finished + */ +- (void)performSelectorOnMainThread: (SEL)selector + withObject: (id)object + waitUntilDone: (BOOL)waitUntilDone; + +/** + * \brief Performs the specified selector on the main thread with the specified + * objects. + * + * \param selector The selector to perform + * \param object1 The first object that is passed to the method specified by the + * selector + * \param object2 The second object that is passed to the method specified by + * the selector + * \param waitUntilDone Whether to wait until the perform finished + */ +- (void)performSelectorOnMainThread: (SEL)selector + withObject: (id)object1 + withObject: (id)object2 + waitUntilDone: (BOOL)waitUntilDone; + /** * \brief Performs the specified selector on the specified thread after the * specified delay. * * \param selector The selector to perform Index: src/OFObject.m ================================================================== --- src/OFObject.m +++ src/OFObject.m @@ -675,10 +675,64 @@ object: object1 object: object2 repeats: NO]; [[thread runLoop] addTimer: timer]; + if (waitUntilDone) + [timer waitUntilDone]; + + objc_autoreleasePoolPop(pool); +} + +- (void)performSelectorOnMainThread: (SEL)selector + waitUntilDone: (BOOL)waitUntilDone +{ + void *pool = objc_autoreleasePoolPush(); + OFTimer *timer = [OFTimer timerWithTimeInterval: 0 + target: self + selector: selector + repeats: NO]; + [[OFRunLoop mainRunLoop] addTimer: timer]; + + if (waitUntilDone) + [timer waitUntilDone]; + + objc_autoreleasePoolPop(pool); +} + +- (void)performSelectorOnMainThread: (SEL)selector + withObject: (id)object + waitUntilDone: (BOOL)waitUntilDone +{ + void *pool = objc_autoreleasePoolPush(); + OFTimer *timer = [OFTimer timerWithTimeInterval: 0 + target: self + selector: selector + object: object + repeats: NO]; + [[OFRunLoop mainRunLoop] addTimer: timer]; + + if (waitUntilDone) + [timer waitUntilDone]; + + objc_autoreleasePoolPop(pool); +} + +- (void)performSelectorOnMainThread: (SEL)selector + withObject: (id)object1 + withObject: (id)object2 + waitUntilDone: (BOOL)waitUntilDone +{ + void *pool = objc_autoreleasePoolPush(); + OFTimer *timer = [OFTimer timerWithTimeInterval: 0 + target: self + selector: selector + object: object1 + object: object2 + repeats: NO]; + [[OFRunLoop mainRunLoop] addTimer: timer]; + if (waitUntilDone) [timer waitUntilDone]; objc_autoreleasePoolPop(pool); }