u8 *metacur;
struct list_head extents;
u16 clusterofs;
-
int seg_num;
#if EROFS_MT_ENABLED
pthread_mutex_t mutex;
pthread_cond_t cond;
- int nfini;
struct erofs_compress_work *mtworks;
#endif
};
struct z_erofs_compress_sctx { /* segment context */
+ struct list_head extents;
struct z_erofs_compress_ictx *ictx;
u8 *queue;
- struct list_head extents;
struct z_erofs_extent_item *pivot;
struct erofs_compress *chandle;
/* Note: struct erofs_work must be the first member */
struct erofs_work work;
struct z_erofs_compress_sctx ctx;
+ pthread_cond_t cond;
struct erofs_compress_work *next;
unsigned int alg_id;
EROFS_NULL_ADDR);
out:
- cwork->errcode = ret;
+ DBG_BUGON(ret > 0);
pthread_mutex_lock(&ictx->mutex);
- if (++ictx->nfini >= ictx->seg_num) {
- DBG_BUGON(ictx->nfini > ictx->seg_num);
- pthread_cond_signal(&ictx->cond);
- }
+ cwork->errcode = ret;
+ pthread_cond_signal(&cwork->cond);
pthread_mutex_unlock(&ictx->mutex);
}
}
}
free(sctx->membuf);
+ sctx->membuf = NULL;
return ret;
}
int i;
ictx->seg_num = nsegs;
- ictx->nfini = 0;
pthread_mutex_init(&ictx->mutex, NULL);
pthread_cond_init(&ictx->cond, NULL);
cur = calloc(1, sizeof(*cur));
if (!cur)
return -ENOMEM;
+ pthread_cond_init(&cur->cond, NULL);
}
*last = cur;
last = &cur->next;
cur->alg_name = ccfg->handle.alg->name;
cur->comp_level = ccfg->handle.compression_level;
cur->dict_size = ccfg->handle.dict_size;
+ cur->errcode = 1; /* mark as "in progress" */
cur->work.fn = z_erofs_mt_workfn;
erofs_queue_work(&z_erofs_mt_ctrl.wq, &cur->work);
erofs_blk_t blkaddr, compressed_blocks = 0;
int ret;
- pthread_mutex_lock(&ictx->mutex);
- while (ictx->nfini < ictx->seg_num)
- pthread_cond_wait(&ictx->cond, &ictx->mutex);
- pthread_mutex_unlock(&ictx->mutex);
-
bh = erofs_balloc(sbi->bmgr, DATA, 0, 0, 0);
if (IS_ERR(bh)) {
ret = PTR_ERR(bh);
cur = head;
head = cur->next;
- if (cur->errcode) {
- ret = cur->errcode;
- } else {
+ pthread_mutex_lock(&ictx->mutex);
+ while ((ret = cur->errcode) > 0)
+ pthread_cond_wait(&cur->cond, &ictx->mutex);
+ pthread_mutex_unlock(&ictx->mutex);
+
+ if (!ret) {
int ret2;
cur->ctx.blkaddr = blkaddr;