[vlc-devel] [PATCH 5/9] VLCKit: There is no reason to have a blocking call to main thread from the event manager thread

Jörg Bleyel joerg at bleyel.de
Fri Jul 11 21:43:42 CEST 2014


Hello all,

performSelectorOnMainThread is not state of the art and slower than
dispatch_async.

---
 Sources/VLCEventManager.m | 39 ++++++++++-----------------------------
 1 file changed, 10 insertions(+), 29 deletions(-)

diff --git a/Sources/VLCEventManager.m b/Sources/VLCEventManager.m
index 65d8007..e9384f4 100644
--- a/Sources/VLCEventManager.m
+++ b/Sources/VLCEventManager.m
@@ -79,10 +79,6 @@ typedef enum
 }
 
 - (void)startEventLoop;
-
-- (void)callDelegateOfObjectAndSendNotificationWithArgs:(message_t
-*)message;
-- (void)callObjectMethodWithArgs:(message_t *)message;
 - (void)callDelegateOfObject:(id)aTarget withDelegateMethod:(SEL)aSelector
 withNotificationName:(NSString *)aNotificationName;
 - (pthread_cond_t *)signalData;
@@ -219,14 +215,16 @@ static void * EventDispatcherMainLoop(void *
user_data)
 
             pthread_mutex_unlock([self queueLock]);
 
-            if (message.type == VLCNotification)
-                [self
performSelectorOnMainThread:@selector(callDelegateOfObjectAndSendNotificatio
nWithArgs:)
-                                       withObject:message
-                                    waitUntilDone: NO];
-            else
-                [self
performSelectorOnMainThread:@selector(callObjectMethodWithArgs:)
-                                       withObject:message
-                                    waitUntilDone: YES];
+            dispatch_async(dispatch_get_main_queue(), ^{
+                if ([self markMessageHandledOnMainThreadIfExists:message])
{
+                    if (message.type == VLCNotification) {
+                        [self callDelegateOfObject:message.target
withDelegateMethod:message.sel withNotificationName:message.name];
+                    } else {
+                        void (*method)(id, SEL, id) = (void (*)(id, SEL,
id))[message.target methodForSelector: message.sel];
+                        method(message.target, message.sel,
message.object);
+                    }
+                }
+            });
         }
     }
 }
@@ -310,23 +308,6 @@ static void * EventDispatcherMainLoop(void * user_data)
     return !cancelled;
 }
 
-- (void)callDelegateOfObjectAndSendNotificationWithArgs:(message_t
*)message
-{
-    // Check that we were not cancelled, ie, target was released
-    if ([self markMessageHandledOnMainThreadIfExists:message])
-        [self callDelegateOfObject:message.target
withDelegateMethod:message.sel withNotificationName:message.name];
-
-}
-
-- (void)callObjectMethodWithArgs:(message_t *)message
-{
-    // Check that we were not cancelled
-    if ([self markMessageHandledOnMainThreadIfExists:message]) {
-        void (*method)(id, SEL, id) = (void (*)(id, SEL,
id))[message.target methodForSelector: message.sel];
-        method(message.target, message.sel, message.object);
-    }
-}
-
 - (void)callDelegateOfObject:(id)aTarget withDelegateMethod:(SEL)aSelector
withNotificationName:(NSString *)aNotificationName
 {
     [[NSNotificationCenter defaultCenter] postNotification: [NSNotification
notificationWithName:aNotificationName object:aTarget]];
-- 
1.8.5.2 (Apple Git-48)



RG
Jörg

Von:  Florent Pillet <fpillet at gmail.com>
Antworten an:  Mailing list for VLC media player developers
<vlc-devel at videolan.org>
Datum:  Freitag, 11. Juli 2014 11:16
An:  Mailing list for VLC media player developers <vlc-devel at videolan.org>
Betreff:  Re: [vlc-devel] [PATCH 5/9] VLCKit: There is no reason to have a
blocking call to main thread from the event manager thread

Yes the execution order is guaranteed if we always push calls to another
thread the same way (either using dispatch or -performSelector). There is no
need to wait for execution completion, IMHO.


On 11 July 2014 08:20, Gleb Pinigin <gpinigin at gmail.com> wrote:
> 
> Hi,
> 
> Yep, most likely.
> 
> Do you see a real reason to make this call synchronous?
> 
> On Jul 11, 2014, at 1:13 PM, David Fuhrmann <david.fuhrmann at gmail.com> wrote:
> 
>> >
>> > Am 11.07.2014 um 04:08 schrieb Gleb Pinigin <gpinigin at gmail.com>:
>> >
>>> >>
>>> >> It's only needed to guarantee that events will be performed on main
>>> thread in dispatch order.
>> >
>> > Hi,
>> >
>> > Even with waitUntilDone: NO, the execution order on the main thread should
>> be retained, no?
>> >
>> > With best regards,
>> > David
>> > _______________________________________________
>> > vlc-devel mailing list
>> > To unsubscribe or modify your subscription options:
>> > https://mailman.videolan.org/listinfo/vlc-devel
> 
> _______________________________________________
> vlc-devel mailing list
> To unsubscribe or modify your subscription options:
> https://mailman.videolan.org/listinfo/vlc-devel



-- 
Florent Pillet

_______________________________________________ vlc-devel mailing list To
unsubscribe or modify your subscription options:
https://mailman.videolan.org/listinfo/vlc-devel

-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://mailman.videolan.org/pipermail/vlc-devel/attachments/20140711/ea7f510c/attachment.html>
-------------- next part --------------
A non-text attachment was scrubbed...
Name: 0001-speedup-message-loop-main-thread-delegate-call.patch
Type: application/octet-stream
Size: 3245 bytes
Desc: not available
URL: <http://mailman.videolan.org/pipermail/vlc-devel/attachments/20140711/ea7f510c/attachment.obj>


More information about the vlc-devel mailing list