1*33b1fccfSAndroid Build Coastguard Worker /* SPDX-License-Identifier: GPL-2.0+ OR Apache-2.0 */ 2*33b1fccfSAndroid Build Coastguard Worker #ifndef __EROFS_WORKQUEUE_H 3*33b1fccfSAndroid Build Coastguard Worker #define __EROFS_WORKQUEUE_H 4*33b1fccfSAndroid Build Coastguard Worker 5*33b1fccfSAndroid Build Coastguard Worker #include "internal.h" 6*33b1fccfSAndroid Build Coastguard Worker 7*33b1fccfSAndroid Build Coastguard Worker struct erofs_workqueue; 8*33b1fccfSAndroid Build Coastguard Worker 9*33b1fccfSAndroid Build Coastguard Worker typedef void *(*erofs_wq_func_t)(struct erofs_workqueue *, void *); 10*33b1fccfSAndroid Build Coastguard Worker 11*33b1fccfSAndroid Build Coastguard Worker struct erofs_work { 12*33b1fccfSAndroid Build Coastguard Worker struct erofs_work *next; 13*33b1fccfSAndroid Build Coastguard Worker void (*fn)(struct erofs_work *work, void *tlsp); 14*33b1fccfSAndroid Build Coastguard Worker }; 15*33b1fccfSAndroid Build Coastguard Worker 16*33b1fccfSAndroid Build Coastguard Worker struct erofs_workqueue { 17*33b1fccfSAndroid Build Coastguard Worker struct erofs_work *head, *tail; 18*33b1fccfSAndroid Build Coastguard Worker pthread_mutex_t lock; 19*33b1fccfSAndroid Build Coastguard Worker pthread_cond_t cond_empty; 20*33b1fccfSAndroid Build Coastguard Worker pthread_cond_t cond_full; 21*33b1fccfSAndroid Build Coastguard Worker pthread_t *workers; 22*33b1fccfSAndroid Build Coastguard Worker unsigned int nworker; 23*33b1fccfSAndroid Build Coastguard Worker unsigned int max_jobs; 24*33b1fccfSAndroid Build Coastguard Worker unsigned int job_count; 25*33b1fccfSAndroid Build Coastguard Worker bool shutdown; 26*33b1fccfSAndroid Build Coastguard Worker erofs_wq_func_t on_start, on_exit; 27*33b1fccfSAndroid Build Coastguard Worker }; 28*33b1fccfSAndroid Build Coastguard Worker 29*33b1fccfSAndroid Build Coastguard Worker int erofs_alloc_workqueue(struct erofs_workqueue *wq, unsigned int nworker, 30*33b1fccfSAndroid Build Coastguard Worker unsigned int max_jobs, erofs_wq_func_t on_start, 31*33b1fccfSAndroid Build Coastguard Worker erofs_wq_func_t on_exit); 32*33b1fccfSAndroid Build Coastguard Worker int erofs_queue_work(struct erofs_workqueue *wq, struct erofs_work *work); 33*33b1fccfSAndroid Build Coastguard Worker int erofs_destroy_workqueue(struct erofs_workqueue *wq); 34*33b1fccfSAndroid Build Coastguard Worker #endif 35