Merge branch 'dev'
This commit is contained in:
commit
6deafdadca
67
bwashm.c
67
bwashm.c
|
|
@ -13,15 +13,15 @@ int bwa_shm_stage(bwaidx_t *idx, const char *hint, const char *_tmpfn)
|
||||||
{
|
{
|
||||||
const char *name;
|
const char *name;
|
||||||
uint8_t *shm, *shm_idx;
|
uint8_t *shm, *shm_idx;
|
||||||
uint16_t *cnt, i;
|
uint16_t *cnt;
|
||||||
int shmid, to_init = 0, l;
|
int shmid, to_init = 0, l;
|
||||||
char path[PATH_MAX + 1], *p, *tmpfn = (char*)_tmpfn;
|
char path[PATH_MAX + 1], *tmpfn = (char*)_tmpfn;
|
||||||
|
|
||||||
if (hint == 0 || hint[0] == 0) return -1;
|
if (hint == 0 || hint[0] == 0) return -1;
|
||||||
for (name = hint + strlen(hint) - 1; name >= hint && *name != '/'; --name);
|
for (name = hint + strlen(hint) - 1; name >= hint && *name != '/'; --name);
|
||||||
++name;
|
++name;
|
||||||
|
|
||||||
if ((shmid = shm_open("/bwactl", O_RDWR, 0444)) < 0) {
|
if ((shmid = shm_open("/bwactl", O_RDWR, 0)) < 0) {
|
||||||
shmid = shm_open("/bwactl", O_CREAT|O_RDWR|O_EXCL, 0644);
|
shmid = shm_open("/bwactl", O_CREAT|O_RDWR|O_EXCL, 0644);
|
||||||
to_init = 1;
|
to_init = 1;
|
||||||
}
|
}
|
||||||
|
|
@ -32,15 +32,6 @@ int bwa_shm_stage(bwaidx_t *idx, const char *hint, const char *_tmpfn)
|
||||||
if (to_init) {
|
if (to_init) {
|
||||||
memset(shm, 0, BWA_CTL_SIZE);
|
memset(shm, 0, BWA_CTL_SIZE);
|
||||||
cnt[1] = 4;
|
cnt[1] = 4;
|
||||||
} else {
|
|
||||||
for (i = 0, p = (char*)shm + 4; i < cnt[0]; ++i) {
|
|
||||||
if (strcmp(p + 8, name) == 0) break;
|
|
||||||
p += 9 + strlen(p + 8);
|
|
||||||
}
|
|
||||||
if (i < cnt[0]) {
|
|
||||||
fprintf(stderr, "[W::%s] index '%s' is already in shared memory\n", __func__, name);
|
|
||||||
return -1;
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
||||||
if (idx->mem == 0) bwa_idx2mem(idx);
|
if (idx->mem == 0) bwa_idx2mem(idx);
|
||||||
|
|
@ -62,15 +53,15 @@ int bwa_shm_stage(bwaidx_t *idx, const char *hint, const char *_tmpfn)
|
||||||
}
|
}
|
||||||
|
|
||||||
strcat(strcpy(path, "/bwaidx-"), name);
|
strcat(strcpy(path, "/bwaidx-"), name);
|
||||||
l = 8 + strlen(name) + 1;
|
|
||||||
if (cnt[1] + l > BWA_CTL_SIZE) return -1;
|
|
||||||
memcpy(shm + cnt[1], &idx->l_mem, 8);
|
|
||||||
memcpy(shm + cnt[1] + 8, name, l - 8);
|
|
||||||
if ((shmid = shm_open(path, O_CREAT|O_RDWR|O_EXCL, 0644)) < 0) {
|
if ((shmid = shm_open(path, O_CREAT|O_RDWR|O_EXCL, 0644)) < 0) {
|
||||||
shm_unlink(path);
|
shm_unlink(path);
|
||||||
perror("shm_open()");
|
perror("shm_open()");
|
||||||
return -1;
|
return -1;
|
||||||
}
|
}
|
||||||
|
l = 8 + strlen(name) + 1;
|
||||||
|
if (cnt[1] + l > BWA_CTL_SIZE) return -1;
|
||||||
|
memcpy(shm + cnt[1], &idx->l_mem, 8);
|
||||||
|
memcpy(shm + cnt[1] + 8, name, l - 8);
|
||||||
cnt[1] += l; ++cnt[0];
|
cnt[1] += l; ++cnt[0];
|
||||||
ftruncate(shmid, idx->l_mem);
|
ftruncate(shmid, idx->l_mem);
|
||||||
shm_idx = mmap(0, idx->l_mem, PROT_READ|PROT_WRITE, MAP_SHARED, shmid, 0);
|
shm_idx = mmap(0, idx->l_mem, PROT_READ|PROT_WRITE, MAP_SHARED, shmid, 0);
|
||||||
|
|
@ -106,7 +97,7 @@ bwaidx_t *bwa_idx_load_from_shm(const char *hint)
|
||||||
if (hint == 0 || hint[0] == 0) return 0;
|
if (hint == 0 || hint[0] == 0) return 0;
|
||||||
for (name = hint + strlen(hint) - 1; name >= hint && *name != '/'; --name);
|
for (name = hint + strlen(hint) - 1; name >= hint && *name != '/'; --name);
|
||||||
++name;
|
++name;
|
||||||
if ((shmid = shm_open("/bwactl", O_RDONLY, 0444)) < 0) return 0;
|
if ((shmid = shm_open("/bwactl", O_RDONLY, 0)) < 0) return 0;
|
||||||
shm = mmap(0, BWA_CTL_SIZE, PROT_READ, MAP_SHARED, shmid, 0);
|
shm = mmap(0, BWA_CTL_SIZE, PROT_READ, MAP_SHARED, shmid, 0);
|
||||||
cnt = (uint16_t*)shm;
|
cnt = (uint16_t*)shm;
|
||||||
if (cnt[0] == 0) return 0;
|
if (cnt[0] == 0) return 0;
|
||||||
|
|
@ -118,7 +109,7 @@ bwaidx_t *bwa_idx_load_from_shm(const char *hint)
|
||||||
if (i == cnt[0]) return 0;
|
if (i == cnt[0]) return 0;
|
||||||
|
|
||||||
strcat(strcpy(path, "/bwaidx-"), name);
|
strcat(strcpy(path, "/bwaidx-"), name);
|
||||||
if ((shmid = shm_open(path, O_RDONLY, 0444)) < 0) return 0;
|
if ((shmid = shm_open(path, O_RDONLY, 0)) < 0) return 0;
|
||||||
shm_idx = mmap(0, l_mem, PROT_READ, MAP_SHARED, shmid, 0);
|
shm_idx = mmap(0, l_mem, PROT_READ, MAP_SHARED, shmid, 0);
|
||||||
idx = calloc(1, sizeof(bwaidx_t));
|
idx = calloc(1, sizeof(bwaidx_t));
|
||||||
bwa_mem2idx(l_mem, shm_idx, idx);
|
bwa_mem2idx(l_mem, shm_idx, idx);
|
||||||
|
|
@ -126,12 +117,32 @@ bwaidx_t *bwa_idx_load_from_shm(const char *hint)
|
||||||
return idx;
|
return idx;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
int bwa_shm_test(const char *hint)
|
||||||
|
{
|
||||||
|
int shmid;
|
||||||
|
uint16_t *cnt, i;
|
||||||
|
char *p, *shm;
|
||||||
|
const char *name;
|
||||||
|
|
||||||
|
if (hint == 0 || hint[0] == 0) return 0;
|
||||||
|
for (name = hint + strlen(hint) - 1; name >= hint && *name != '/'; --name);
|
||||||
|
++name;
|
||||||
|
if ((shmid = shm_open("/bwactl", O_RDONLY, 0)) < 0) return 0;
|
||||||
|
shm = mmap(0, BWA_CTL_SIZE, PROT_READ, MAP_SHARED, shmid, 0);
|
||||||
|
cnt = (uint16_t*)shm;
|
||||||
|
for (i = 0, p = shm + 4; i < cnt[0]; ++i) {
|
||||||
|
if (strcmp(p + 8, name) == 0) return 1;
|
||||||
|
p += strlen(p) + 9;
|
||||||
|
}
|
||||||
|
return 0;
|
||||||
|
}
|
||||||
|
|
||||||
int bwa_shm_list(void)
|
int bwa_shm_list(void)
|
||||||
{
|
{
|
||||||
int shmid;
|
int shmid;
|
||||||
uint16_t *cnt, i;
|
uint16_t *cnt, i;
|
||||||
char *p, *shm;
|
char *p, *shm;
|
||||||
if ((shmid = shm_open("/bwactl", O_RDONLY, 0444)) < 0) return -1;
|
if ((shmid = shm_open("/bwactl", O_RDONLY, 0)) < 0) return -1;
|
||||||
shm = mmap(0, BWA_CTL_SIZE, PROT_READ, MAP_SHARED, shmid, 0);
|
shm = mmap(0, BWA_CTL_SIZE, PROT_READ, MAP_SHARED, shmid, 0);
|
||||||
cnt = (uint16_t*)shm;
|
cnt = (uint16_t*)shm;
|
||||||
for (i = 0, p = shm + 4; i < cnt[0]; ++i) {
|
for (i = 0, p = shm + 4; i < cnt[0]; ++i) {
|
||||||
|
|
@ -150,7 +161,7 @@ int bwa_shm_destroy(void)
|
||||||
char *p, *shm;
|
char *p, *shm;
|
||||||
char path[PATH_MAX + 1];
|
char path[PATH_MAX + 1];
|
||||||
|
|
||||||
if ((shmid = shm_open("/bwactl", O_RDONLY, 0444)) < 0) return -1;
|
if ((shmid = shm_open("/bwactl", O_RDONLY, 0)) < 0) return -1;
|
||||||
shm = mmap(0, BWA_CTL_SIZE, PROT_READ, MAP_SHARED, shmid, 0);
|
shm = mmap(0, BWA_CTL_SIZE, PROT_READ, MAP_SHARED, shmid, 0);
|
||||||
cnt = (uint16_t*)shm;
|
cnt = (uint16_t*)shm;
|
||||||
for (i = 0, p = shm + 4; i < cnt[0]; ++i) {
|
for (i = 0, p = shm + 4; i < cnt[0]; ++i) {
|
||||||
|
|
@ -186,13 +197,15 @@ int main_shm(int argc, char *argv[])
|
||||||
return 1;
|
return 1;
|
||||||
}
|
}
|
||||||
if (optind < argc) {
|
if (optind < argc) {
|
||||||
bwaidx_t *idx;
|
if (bwa_shm_test(argv[optind]) == 0) {
|
||||||
idx = bwa_idx_load_from_disk(argv[optind], BWA_IDX_ALL);
|
bwaidx_t *idx;
|
||||||
if (bwa_shm_stage(idx, argv[optind], tmpfn) < 0) {
|
idx = bwa_idx_load_from_disk(argv[optind], BWA_IDX_ALL);
|
||||||
fprintf(stderr, "[E::%s] failed to stage the index in shared memory\n", __func__);
|
if (bwa_shm_stage(idx, argv[optind], tmpfn) < 0) {
|
||||||
ret = 1;
|
fprintf(stderr, "[E::%s] failed to stage the index in shared memory\n", __func__);
|
||||||
}
|
ret = 1;
|
||||||
bwa_idx_destroy(idx);
|
}
|
||||||
|
bwa_idx_destroy(idx);
|
||||||
|
} else fprintf(stderr, "[M::%s] index '%s' is already in shared memory\n", __func__, argv[optind]);
|
||||||
}
|
}
|
||||||
if (to_list) bwa_shm_list();
|
if (to_list) bwa_shm_list();
|
||||||
if (to_drop) bwa_shm_destroy();
|
if (to_drop) bwa_shm_destroy();
|
||||||
|
|
|
||||||
2
main.c
2
main.c
|
|
@ -4,7 +4,7 @@
|
||||||
#include "utils.h"
|
#include "utils.h"
|
||||||
|
|
||||||
#ifndef PACKAGE_VERSION
|
#ifndef PACKAGE_VERSION
|
||||||
#define PACKAGE_VERSION "0.7.10-r907-dirty"
|
#define PACKAGE_VERSION "0.7.10-r912-dirty"
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
int bwa_fa2pac(int argc, char *argv[]);
|
int bwa_fa2pac(int argc, char *argv[]);
|
||||||
|
|
|
||||||
Loading…
Reference in New Issue