Skip to content

Commit acc28ac

Browse files
vasudeva8whitwham
authored andcommitted
change to fail on unnecessary hts_set_threads/_pool invocation
1 parent 396e5c9 commit acc28ac

File tree

3 files changed

+14
-4
lines changed

3 files changed

+14
-4
lines changed

bgzf.c

Lines changed: 5 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1741,6 +1741,8 @@ int bgzf_thread_pool(BGZF *fp, hts_tpool *pool, int qsize) {
17411741
// No gain from multi-threading when not compressed
17421742
if (!fp->is_compressed)
17431743
return 0;
1744+
if (fp->mt)
1745+
return -2; //already exists!
17441746

17451747
mtaux_t *mt;
17461748
mt = (mtaux_t*)calloc(1, sizeof(mtaux_t));
@@ -1789,9 +1791,10 @@ int bgzf_mt(BGZF *fp, int n_threads, int n_sub_blks)
17891791
if (!p)
17901792
return -1;
17911793

1792-
if (bgzf_thread_pool(fp, p, 0) != 0) {
1794+
int ret = 0;
1795+
if ((ret = bgzf_thread_pool(fp, p, 0)) < 0) {
17931796
hts_tpool_destroy(p);
1794-
return -1;
1797+
return ret;
17951798
}
17961799

17971800
fp->mt->own_pool = 1;

cram/cram_io.c

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -5868,6 +5868,8 @@ int cram_set_voption(cram_fd *fd, enum hts_fmt_option opt, va_list args) {
58685868

58695869
case CRAM_OPT_NTHREADS: {
58705870
int nthreads = va_arg(args, int);
5871+
if (fd->pool)
5872+
return -2; //already exists!
58715873
if (nthreads >= 1) {
58725874
if (!(fd->pool = hts_tpool_init(nthreads)))
58735875
return -1;
@@ -5881,6 +5883,8 @@ int cram_set_voption(cram_fd *fd, enum hts_fmt_option opt, va_list args) {
58815883

58825884
case CRAM_OPT_THREAD_POOL: {
58835885
htsThreadPool *p = va_arg(args, htsThreadPool *);
5886+
if (fd->pool)
5887+
return -2; //already exists!
58845888
fd->pool = p ? p->pool : NULL;
58855889
if (fd->pool) {
58865890
fd->rqueue = hts_tpool_process_init(fd->pool,

sam.c

Lines changed: 5 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -3713,7 +3713,7 @@ static void *sam_format_worker(void *arg) {
37133713

37143714
int sam_set_thread_pool(htsFile *fp, htsThreadPool *p) {
37153715
if (fp->state)
3716-
return 0;
3716+
return -2; //already exists!
37173717

37183718
if (!(fp->state = sam_state_create(fp)))
37193719
return -1;
@@ -3747,8 +3747,11 @@ int sam_set_threads(htsFile *fp, int nthreads) {
37473747
p.qsize = nthreads*2;
37483748

37493749
int ret = sam_set_thread_pool(fp, &p);
3750-
if (ret < 0)
3750+
if (ret < 0) {
3751+
if (p.pool)
3752+
hts_tpool_destroy(p.pool);
37513753
return ret;
3754+
}
37523755

37533756
SAM_state *fd = (SAM_state *)fp->state;
37543757
fd->own_pool = 1;

0 commit comments

Comments
 (0)