[PATCH 1/7] erofs-utils: introduce multi-threading framework

Gao Xiang hsiangkao at linux.alibaba.com
Wed Feb 7 14:55:15 AEDT 2024


Hi,

On 2024/2/4 18:33, Yifan Zhao wrote:
> From: Gao Xiang <hsiangkao at linux.alibaba.com>
> 
> Add a workqueue implementation based on xfsprogs for multi-threading
> support.
> 
> Signed-off-by: Gao Xiang <hsiangkao at linux.alibaba.com>
> ---

...


> --- /dev/null
> +++ b/include/erofs/workqueue.h
> @@ -0,0 +1,44 @@
> +/* SPDX-License-Identifier: GPL-2.0+ */
> +/*
> + * Copyright (C) 2017 Oracle.  All Rights Reserved.
> + * Author: Darrick J. Wong <darrick.wong at oracle.com>
> + */

Since it was taken from xfsprogs and the majority of
erofs-utils needs to be licensed with (.. OR Apache 2.0)
too.

I've asked Darrick to confirm this if the relicensing
(GPL-2.0+ OR Apache-2.0) is possible, since basically
it's no need to mimic another not good one for this...

Thanks,
Gao Xiang

> +#ifndef __EROFS_WORKQUEUE_H
> +#define __EROFS_WORKQUEUE_H
> +
> +#include "internal.h"
> +
> +struct erofs_workqueue;
> +struct erofs_work;
> +
> +typedef void erofs_workqueue_func_t(struct erofs_workqueue *wq,
> +				    struct erofs_work *work);
> +
> +struct erofs_work {
> +	struct erofs_workqueue	*queue;
> +	struct erofs_work	*next;
> +	erofs_workqueue_func_t	*function;
> +};
> +
> +struct erofs_workqueue {
> +	pthread_t		*threads;
> +	struct erofs_work	*next_item;
> +	struct erofs_work	*last_item;
> +	pthread_mutex_t		lock;
> +	pthread_cond_t		wakeup;
> +	unsigned int		item_count;
> +	unsigned int		thread_count;
> +	bool			terminate;
> +	bool			terminated;
> +	int			max_queued;
> +	pthread_cond_t		queue_full;
> +};
> +
> +int erofs_workqueue_create(struct erofs_workqueue *wq,
> +			   unsigned int nr_workers, unsigned int max_queue);
> +int erofs_workqueue_add(struct erofs_workqueue	*wq,
> +			struct erofs_work *wi);
> +int erofs_workqueue_terminate(struct erofs_workqueue *wq);
> +void erofs_workqueue_destroy(struct erofs_workqueue *wq);
> +
> +#endif
> diff --git a/lib/Makefile.am b/lib/Makefile.am
> index 54b9c9c..7307f7b 100644
> --- a/lib/Makefile.am
> +++ b/lib/Makefile.am
> @@ -53,3 +53,7 @@ liberofs_la_SOURCES += kite_deflate.c compressor_deflate.c
>   if ENABLE_LIBDEFLATE
>   liberofs_la_SOURCES += compressor_libdeflate.c
>   endif
> +if ENABLE_EROFS_MT
> +liberofs_la_CFLAGS += -lpthread
> +liberofs_la_SOURCES += workqueue.c
> +endif
> diff --git a/lib/workqueue.c b/lib/workqueue.c
> new file mode 100644
> index 0000000..6573821
> --- /dev/null
> +++ b/lib/workqueue.c
> @@ -0,0 +1,205 @@
> +// SPDX-License-Identifier: GPL-2.0+
> +/*
> + * Copyright (C) 2017 Oracle.  All Rights Reserved.
> + * Author: Darrick J. Wong <darrick.wong at oracle.com>
> + */



More information about the Linux-erofs mailing list