[vlc-devel] [RFC v2 1/2] executor: introduce new executor API

Romain Vimont rom1v at videolabs.io
Wed Sep 2 14:22:26 CEST 2020


On Wed, Sep 02, 2020 at 02:11:15PM +0200, Steve Lhomme wrote:
> An even simpler example, run the same task twice sequentially:
> 
> struct my_task {
>     vlc_executor_t *executor;
>     bool first;
>     char *str;
>     struct vlc_runnable runnable;
> };
> 
> static void Run(void *userdata)
> {
>     struct my_task *task = userdata;
> 
>     printf("start of %s\n", task->str);
>     vlc_tick_sleep(VLC_TICK_FROM_SEC(3)); // long action
>     printf("end of %s\n", task->str);
> 
>     if (task->first)
>     {
>         task->first = false;
>         vlc_executor_Submit(task->executor, &task->runnable);
>     }
>     else
>     {
>         free(task->str);
>         free(task);
>     }
> }
> 
> void foo(vlc_executor_t *executor, const char *str)
> {
>     // no error handling for brevity
>     struct my_task *task = malloc(sizeof(*task));
>     task->str = strdup(str);
>     task->first = true;
>     task->executor = executor;
>     task->runnable.run = Run;
>     task->runnable.userdata = task;
>     vlc_executor_Submit(executor, &task->runnable);
> 
>     vlc_executor_Delete(executor);
> }
> 
> Is it possible to submit a vlc_runnable that is already in use by the
> executor ?

It is incorrect to submit a runnable already submitted that is still in
the pending queue (i.e. not canceled or started). This is due to the
intrusive linked list of runnables.

It is strongly discouraged not to submit a runnable that its currently
running on the executor (unless you are prepared for the run() callback
to be run several times in parallel).

For simplicity, it is discouraged to submit a runnable previously
submitted.

> _______________________________________________
> 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