* Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston MA 02110-1301, USA.
*****************************************************************************/
+#include <assert.h>
+
#include <vlc/libvlc.h>
#include "libvlc_internal.h"
vlc_mutex_t lock;
vlc_cond_t signal;
vlc_thread_t thread;
+ bool is_idle;
+ vlc_cond_t signal_idle;
+ vlc_threadvar_t is_asynch_dispatch_thread_var;
};
/*
vlc_mutex_destroy(&queue(p_em)->lock);
vlc_cond_destroy(&queue(p_em)->signal);
+ vlc_cond_destroy(&queue(p_em)->signal_idle);
+ vlc_threadvar_delete(&queue(p_em)->is_asynch_dispatch_thread_var);
struct queue_elmt * iter = queue(p_em)->elements;
while (iter) {
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);
}
/**************************************************************************
queue_lock(p_em);
pop_listener(p_em, listener);
+
+ bool is_asynch_dispatch_thread = vlc_threadvar_get(queue(p_em)->is_asynch_dispatch_thread_var);
+
+ // Wait for the asynch_loop to have processed all events.
+ if(!queue(p_em)->is_idle && !is_asynch_dispatch_thread)
+ {
+ vlc_cond_wait(&queue(p_em)->signal_idle, &queue(p_em)->lock);
+ assert(queue(p_em)->is_idle);
+ }
queue_unlock(p_em);
}
libvlc_event_listener_t listener;
libvlc_event_t event;
+ vlc_threadvar_set(queue(p_em)->is_asynch_dispatch_thread_var, (void*)true);
+
queue_lock(p_em);
while (true) {
int has_listener = pop(p_em, &listener, &event);
}
else
{
+ queue(p_em)->is_idle = true;
+
mutex_cleanup_push(&queue(p_em)->lock);
+ 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;
}
}
queue_unlock(p_em);