-static void *mt_worker(void *data)
-{
- int i, stop = 0;
- worker_t *w = (worker_t*)data;
- for (;;) {
- int tmp;
- pthread_mutex_lock(&w->mt->lock);
- while (!w->toproc && !w->mt->done)
- pthread_cond_wait(&w->mt->cv, &w->mt->lock);
- if (w->mt->done) stop = 1;
- w->toproc = 0;
- pthread_mutex_unlock(&w->mt->lock);
- if (stop) break;
- w->errcode = 0;
- for (i = w->i; i < w->mt->curr; i += w->mt->n_threads) {
- int clen = BGZF_MAX_BLOCK_SIZE;
+static int worker_aux(worker_t *w)
+{
+ int i, tmp, stop = 0;
+ // wait for condition: to process or all done
+ pthread_mutex_lock(&w->mt->lock);
+ while (!w->toproc && !w->mt->done)
+ pthread_cond_wait(&w->mt->cv, &w->mt->lock);
+ if (w->mt->done) stop = 1;
+ w->toproc = 0;
+ pthread_mutex_unlock(&w->mt->lock);
+ if (stop) return 1; // to quit the thread
+ w->errcode = 0;
+ for (i = w->i; i < w->mt->curr; i += w->mt->n_threads) {
+ int clen = BGZF_MAX_BLOCK_SIZE;