]> git.sesse.net Git - vlc/blobdiff - src/control/event_async.c
GLX: remove MIT-SHM support infrastructure
[vlc] / src / control / event_async.c
index e8f9a0851fdbc8b110a39119a4839148901452aa..ecb6fa8890e8259c0b9fa94dcc3c1f71efd9b322 100644 (file)
  * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston MA 02110-1301, USA.
  *****************************************************************************/
 
+#ifdef HAVE_CONFIG_H
+# include "config.h"
+#endif
+
 #include <assert.h>
 
 #include <vlc/libvlc.h>
@@ -73,12 +77,12 @@ static void push(libvlc_event_manager_t * p_em, libvlc_event_listener_t * listen
     static const long MaxQueuedItem = 300000;
     long count = 0;
 #endif
-    
+
     struct queue_elmt * elmt = malloc(sizeof(struct queue_elmt));
     elmt->listener = *listener;
     elmt->event = *event;
     elmt->next = NULL;
-    
+
     /* Append to the end of the queue */
     struct queue_elmt * iter = queue(p_em)->elements;
     if(!iter)
@@ -118,7 +122,7 @@ static bool pop(libvlc_event_manager_t * p_em, libvlc_event_listener_t * listene
 
     *listener = queue(p_em)->elements->listener;
     *event = queue(p_em)->elements->event;
-    
+
     struct queue_elmt * elmt = queue(p_em)->elements;
     queue(p_em)->elements = elmt->next;
     free(elmt);
@@ -155,9 +159,15 @@ static void pop_listener(libvlc_event_manager_t * p_em, libvlc_event_listener_t
  **************************************************************************/
 void
 libvlc_event_async_fini(libvlc_event_manager_t * p_em)
-{    
+{
     if(!is_queue_initialized(p_em)) return;
-    
+
+    if(current_thread_is_asynch_thread(p_em))
+    {
+        fprintf(stderr, "*** Error: releasing the last reference of the observed object from its callback thread is not (yet!) supported\n");
+        abort();
+    }
+
     vlc_thread_t thread = queue(p_em)->thread;
     if(thread)
     {
@@ -176,7 +186,7 @@ libvlc_event_async_fini(libvlc_event_manager_t * p_em)
         iter = iter->next;
         free(elemt_to_delete);
     }
-    
+
     free(queue(p_em));
 }
 
@@ -190,7 +200,14 @@ libvlc_event_async_init(libvlc_event_manager_t * p_em)
 {
     p_em->async_event_queue = calloc(1, sizeof(struct libvlc_event_async_queue));
 
-    int error = vlc_clone (&queue(p_em)->thread, event_async_loop, p_em, VLC_THREAD_PRIORITY_LOW);
+    int error = vlc_threadvar_create(&queue(p_em)->is_asynch_dispatch_thread_var, NULL);
+    assert(!error);
+
+    vlc_mutex_init(&queue(p_em)->lock);
+    vlc_cond_init(&queue(p_em)->signal);
+    vlc_cond_init(&queue(p_em)->signal_idle);
+
+    error = vlc_clone (&queue(p_em)->thread, event_async_loop, p_em, VLC_THREAD_PRIORITY_LOW);
     if(error)
     {
         free(p_em->async_event_queue);
@@ -198,11 +215,6 @@ libvlc_event_async_init(libvlc_event_manager_t * p_em)
         return;
     }
 
-    vlc_mutex_init(&queue(p_em)->lock);
-    vlc_cond_init(&queue(p_em)->signal);
-    vlc_cond_init(&queue(p_em)->signal_idle);
-    error = vlc_threadvar_create(&queue(p_em)->is_asynch_dispatch_thread_var, NULL);
-    assert(!error);
 }
 
 /**************************************************************************
@@ -217,7 +229,7 @@ libvlc_event_async_ensure_listener_removal(libvlc_event_manager_t * p_em, libvlc
 
     queue_lock(p_em);
     pop_listener(p_em, listener);
-    
+
     // Wait for the asynch_loop to have processed all events.
     if(!current_thread_is_asynch_thread(p_em))
     {
@@ -258,7 +270,7 @@ static void * event_async_loop(void * arg)
     libvlc_event_listener_t listener;
     libvlc_event_t event;
 
-    vlc_threadvar_set(queue(p_em)->is_asynch_dispatch_thread_var, (void*)true);
+    vlc_threadvar_set(queue(p_em)->is_asynch_dispatch_thread_var, p_em);
 
     queue_lock(p_em);
     while (true) {
@@ -278,7 +290,7 @@ static void * event_async_loop(void * arg)
             vlc_cond_broadcast(&queue(p_em)->signal_idle); // We'll be idle
             vlc_cond_wait(&queue(p_em)->signal, &queue(p_em)->lock);
             vlc_cleanup_pop();
-            
+
             queue(p_em)->is_idle = false;
         }
     }