Re: [RFC PATCH v2 04/10] perf workqueue: add threadpool execute and wait functions

From: Namhyung Kim
Date: Fri Aug 06 2021 - 22:56:29 EST


On Fri, Jul 30, 2021 at 8:34 AM Riccardo Mancini <rickyman7@xxxxxxxxx> wrote:
>
> This patch adds:
> - threadpool__execute: assigns a task to the threads to execute
> asynchronously.
> - threadpool__wait: waits for the task to complete on all threads.
> Furthermore, testing for these new functions is added.
>
> This patch completes the threadpool.
>
> Signed-off-by: Riccardo Mancini <rickyman7@xxxxxxxxx>
> ---

[SNIP]
> +/**
> + * threadpool__wake_thread - send wake msg to @thread
> + *
> + * This function does not wait for the thread to actually wake
> + * NB: call only from main thread!
> + */
> +static int threadpool__wake_thread(struct threadpool_entry *thread)

Same here. You can pass pool and idx instead.

Thanks,
Namhyung


> +{
> + int res;
> + enum threadpool_msg msg = THREADPOOL_MSG__WAKE;
> +
> + res = writen(thread->pipes.cmd[1], &msg, sizeof(msg));
> + if (res < 0) {
> + pr_debug2("threadpool: error sending wake msg: %s\n", strerror(errno));
> + return -THREADPOOL_ERROR__WRITEPIPE;
> + }
> +
> + pr_debug2("threadpool: sent wake msg %s to tid=%d\n",
> + threadpool_msg_tags[msg], thread->tid);
> + return 0;
> +}
> +