]> git.sesse.net Git - vlc/blobdiff - src/misc/events.c
es_format: avoid copy in video_format_IsSimilar() if possible
[vlc] / src / misc / events.c
index e3b1ee003e0a75a8f0119ef3093c4f638e5663a3..fb2a04df3accfd0cdac885211dce36c37aa5fdb3 100644 (file)
@@ -3,24 +3,24 @@
  * This library provides an interface to the send and receive events.
  * It is more lightweight than variable based callback.
  *****************************************************************************
- * Copyright (C) 1998-2005 the VideoLAN team
+ * Copyright (C) 1998-2005 VLC authors and VideoLAN
  * $Id$
  *
  * Authors: Pierre d'Herbemont <pdherbemont # videolan.org >
  *
- * This program is free software; you can redistribute it and/or modify
- * it under the terms of the GNU General Public License as published by
- * the Free Software Foundation; either version 2 of the License, or
+ * This program is free software; you can redistribute it and/or modify it
+ * under the terms of the GNU Lesser General Public License as published by
+ * the Free Software Foundation; either version 2.1 of the License, or
  * (at your option) any later version.
  *
  * This program is distributed in the hope that it will be useful,
  * but WITHOUT ANY WARRANTY; without even the implied warranty of
- * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
- * GNU General Public License for more details.
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+ * GNU Lesser General Public License for more details.
  *
- * You should have received a copy of the GNU General Public License
- * along with this program; if not, write to the Free Software
- * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston MA 02110-1301, USA.
+ * You should have received a copy of the GNU Lesser General Public License
+ * along with this program; if not, write to the Free Software Foundation,
+ * Inc., 51 Franklin Street, Fifth Floor, Boston MA 02110-1301, USA.
  *****************************************************************************/
 
 /*****************************************************************************
@@ -170,7 +170,9 @@ void vlc_event_send( vlc_event_manager_t * p_em,
     /* Fill event with the sending object now */
     p_event->p_obj = p_em->p_obj;
 
+    vlc_mutex_lock( &p_em->event_sending_lock ) ;
     vlc_mutex_lock( &p_em->object_lock );
+
     FOREACH_ARRAY( listeners_group, p_em->listeners_groups )
         if( listeners_group->event_type == p_event->type )
         {
@@ -184,6 +186,7 @@ void vlc_event_send( vlc_event_manager_t * p_em,
             if( !array_of_cached_listeners )
             {
                 vlc_mutex_unlock( &p_em->object_lock );
+                vlc_mutex_unlock( &p_em->event_sending_lock ) ;
                 return;
             }
 
@@ -196,28 +199,31 @@ void vlc_event_send( vlc_event_manager_t * p_em,
             break;
         }
     FOREACH_END()
+
+    /* Track item removed from *this* thread, with a simple flag. Indeed
+     * event_sending_lock is a recursive lock. This has the advantage of
+     * allowing to remove an event listener from within a callback */
+    listeners_group->b_sublistener_removed = false;
+
     vlc_mutex_unlock( &p_em->object_lock );
+
     /* Call the function attached */
     cached_listener = array_of_cached_listeners;
 
     if( !listeners_group || !array_of_cached_listeners )
     {
         free( array_of_cached_listeners );
+        vlc_mutex_unlock( &p_em->event_sending_lock );
         return;
     }
 
-    vlc_mutex_lock( &p_em->event_sending_lock ) ;
-
-    /* Track item removed from *this* thread, with a simple flag */
-    listeners_group->b_sublistener_removed = false;
 
     for( i = 0; i < i_cached_listeners; i++ )
     {
-        /* No need to lock on listeners_group, a listener group can't be removed */
         if( listeners_group->b_sublistener_removed )
         {
-            /* If a callback was removed, this gets called */
+            /* If a callback was removed inside one of our callback, this gets
+            * called */
             bool valid_listener;
             vlc_mutex_lock( &p_em->object_lock );
             valid_listener = group_contains_listener( listeners_group, cached_listener );