[vlc-devel] [PATCH 3/3] fingerprinter: use vlc_cond_t instead of sleep
Thomas Guillem
thomas at gllm.fr
Mon Mar 23 09:36:35 CET 2020
On Sun, Mar 22, 2020, at 16:21, Alexandre Janniaux wrote:
> Instead of checking new requests every seconds, wait for actual new
> requests to be enqueued before trying to do any processing. This avoid
> the harmful sleep warning on vlc_tick_sleep as well as providing better
> latency for new fingerprinting requests on a cold fingerprinter.
> ---
> modules/misc/fingerprinter.c | 22 +++++++++++++++-------
> 1 file changed, 15 insertions(+), 7 deletions(-)
>
> diff --git a/modules/misc/fingerprinter.c b/modules/misc/fingerprinter.c
> index 99a05346f0..18cc83bc2c 100644
> --- a/modules/misc/fingerprinter.c
> +++ b/modules/misc/fingerprinter.c
> @@ -51,6 +51,8 @@ struct fingerprinter_sys_t
> vlc_mutex_t lock;
> } incoming, results;
>
> + vlc_cond_t incoming_cond;
> +
> struct
> {
> vlc_array_t queue;
> @@ -85,14 +87,13 @@ static int EnqueueRequest( fingerprinter_thread_t
> *f, fingerprint_request_t *r )
> fingerprinter_sys_t *p_sys = f->p_sys;
> vlc_mutex_lock( &p_sys->incoming.lock );
> int i_ret = vlc_array_append( &p_sys->incoming.queue, r );
> + vlc_cond_signal( &p_sys->incoming_cond );
> vlc_mutex_unlock( &p_sys->incoming.lock );
> return i_ret;
> }
>
> static void QueueIncomingRequests( fingerprinter_sys_t *p_sys )
> {
> - vlc_mutex_lock( &p_sys->incoming.lock );
> -
> for( size_t i = vlc_array_count( &p_sys->incoming.queue ); i > 0 ;
> i-- )
> {
> fingerprint_request_t *r = vlc_array_item_at_index(
> &p_sys->incoming.queue, i - 1 );
> @@ -100,7 +101,6 @@ static void QueueIncomingRequests(
> fingerprinter_sys_t *p_sys )
> fingerprint_request_Delete( r );
> }
> vlc_array_clear( &p_sys->incoming.queue );
> - vlc_mutex_unlock(&p_sys->incoming.lock);
> }
>
> static fingerprint_request_t * GetResult( fingerprinter_thread_t *f )
> @@ -250,6 +250,7 @@ static int Open(vlc_object_t *p_this)
>
> vlc_array_init( &p_sys->incoming.queue );
> vlc_mutex_init( &p_sys->incoming.lock );
> + vlc_cond_init( &p_sys->incoming_cond );
>
> vlc_array_init( &p_sys->processing.queue );
> vlc_cond_init( &p_sys->processing.cond );
> @@ -344,12 +345,19 @@ static void *Run( void *opaque )
> /* main loop */
> for (;;)
> {
> - vlc_tick_sleep( VLC_TICK_FROM_SEC(1) );
> -
> - QueueIncomingRequests( p_sys );
> -
> vlc_testcancel();
>
> + vlc_mutex_lock( &p_sys->incoming.lock );
> + mutex_cleanup_push( &p_sys->incoming.lock );
> +
> + while( vlc_array_count( &p_sys->incoming.queue ) == 0 )
> + vlc_cond_wait( &p_sys->incoming_cond, &p_sys->incoming.lock );
> +
> + QueueIncomingRequests( p_sys );
> +
> + vlc_cleanup_pop();
Is it possible to remove the thread cancel usage too ?
> + vlc_mutex_unlock( &p_sys->incoming.lock );
> +
> bool results_available = false;
> while( vlc_array_count( &p_sys->processing.queue ) )
> {
> --
> 2.25.2
>
> _______________________________________________
> vlc-devel mailing list
> To unsubscribe or modify your subscription options:
> https://mailman.videolan.org/listinfo/vlc-devel
More information about the vlc-devel
mailing list