remove worker mutex
This commit is contained in:
parent
ebac0d06a6
commit
e6fa1c7079
@ -289,7 +289,6 @@ int hisat_3n_table()
|
|||||||
// then load a new reference chromosome.
|
// then load a new reference chromosome.
|
||||||
auto old = positions->chromosome;
|
auto old = positions->chromosome;
|
||||||
if (samChromosome != (old ? *old : "")) {
|
if (samChromosome != (old ? *old : "")) {
|
||||||
positions->appendingFinished();
|
|
||||||
positions->moveAllToOutput();
|
positions->moveAllToOutput();
|
||||||
positions->loadNewChromosome(std::move(samChromosome));
|
positions->loadNewChromosome(std::move(samChromosome));
|
||||||
reloadPos = loadingBlockSize;
|
reloadPos = loadingBlockSize;
|
||||||
@ -297,7 +296,6 @@ int hisat_3n_table()
|
|||||||
}
|
}
|
||||||
// if the samPos is larger than reloadPos, load 1 loadingBlockSize bp in from reference.
|
// if the samPos is larger than reloadPos, load 1 loadingBlockSize bp in from reference.
|
||||||
while (samPos > reloadPos) {
|
while (samPos > reloadPos) {
|
||||||
positions->appendingFinished();
|
|
||||||
positions->moveBlockToOutput();
|
positions->moveBlockToOutput();
|
||||||
positions->loadMore();
|
positions->loadMore();
|
||||||
reloadPos += loadingBlockSize;
|
reloadPos += loadingBlockSize;
|
||||||
@ -319,8 +317,6 @@ int hisat_3n_table()
|
|||||||
workers[i].join();
|
workers[i].join();
|
||||||
}
|
}
|
||||||
|
|
||||||
// make sure all workers finished their appending work.
|
|
||||||
positions->appendingFinished();
|
|
||||||
// move all position to outputPool
|
// move all position to outputPool
|
||||||
positions->moveAllToOutput();
|
positions->moveAllToOutput();
|
||||||
// wait until outputPool is empty
|
// wait until outputPool is empty
|
||||||
|
@ -199,7 +199,6 @@ public:
|
|||||||
mutex mutex_;
|
mutex mutex_;
|
||||||
long long int refCoveredPosition; // this is the last position in reference chromosome we loaded in refPositions.
|
long long int refCoveredPosition; // this is the last position in reference chromosome we loaded in refPositions.
|
||||||
ifstream refFile;
|
ifstream refFile;
|
||||||
vector<mutex*> workerLock; // one lock for one worker thread.
|
|
||||||
int nThreads = 1;
|
int nThreads = 1;
|
||||||
ChromosomeFilePositions chromosomePos; // store the chromosome name and it's streamPos. To quickly find new chromosome in file.
|
ChromosomeFilePositions chromosomePos; // store the chromosome name and it's streamPos. To quickly find new chromosome in file.
|
||||||
bool addedChrName = false;
|
bool addedChrName = false;
|
||||||
@ -209,23 +208,11 @@ public:
|
|||||||
nThreads = inputNThreads;
|
nThreads = inputNThreads;
|
||||||
addedChrName = inputAddedChrName;
|
addedChrName = inputAddedChrName;
|
||||||
removedChrName = inputRemovedChrName;
|
removedChrName = inputRemovedChrName;
|
||||||
for (int i = 0; i < nThreads; i++) {
|
|
||||||
workerLock.push_back(new mutex);
|
|
||||||
}
|
|
||||||
refFile.open(inputRefFileName, ios_base::in);
|
refFile.open(inputRefFileName, ios_base::in);
|
||||||
LoadChromosomeNamesPos();
|
LoadChromosomeNamesPos();
|
||||||
}
|
}
|
||||||
|
|
||||||
~Positions() {
|
~Positions() = default;
|
||||||
for (int i = 0; i < workerLock.size(); i++) {
|
|
||||||
delete workerLock[i];
|
|
||||||
}
|
|
||||||
Position* pos;
|
|
||||||
// freePositionPool.close();
|
|
||||||
// while(freePositionPool.recv(pos)) {
|
|
||||||
// delete pos;
|
|
||||||
// }
|
|
||||||
}
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* given the target Position output the corresponding position index in refPositions.
|
* given the target Position output the corresponding position index in refPositions.
|
||||||
@ -309,16 +296,6 @@ public:
|
|||||||
location += line.size();
|
location += line.size();
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
|
||||||
* if we can go through all the workerLock, that means no worker is appending new position.
|
|
||||||
*/
|
|
||||||
void appendingFinished() {
|
|
||||||
for (int i = 0; i < nThreads; i++) {
|
|
||||||
workerLock[i]->lock();
|
|
||||||
workerLock[i]->unlock();
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* the output function for output thread.
|
* the output function for output thread.
|
||||||
*/
|
*/
|
||||||
@ -346,10 +323,22 @@ public:
|
|||||||
tableFile.close();
|
tableFile.close();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
/**
|
||||||
|
* if we can go through all the workerLock, that means no worker is appending new position.
|
||||||
|
*/
|
||||||
|
void appendingFinished() {
|
||||||
|
while (!linePool.empty()) {
|
||||||
|
this_thread::sleep_for (std::chrono::microseconds(1));
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* move the position which position smaller than refCoveredPosition - loadingBlockSize, output it.
|
* move the position which position smaller than refCoveredPosition - loadingBlockSize, output it.
|
||||||
*/
|
*/
|
||||||
void moveBlockToOutput() {
|
void moveBlockToOutput() {
|
||||||
|
appendingFinished();
|
||||||
if (refPositions.empty()) {
|
if (refPositions.empty()) {
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
@ -372,6 +361,7 @@ public:
|
|||||||
* move all the refPosition into output pool.
|
* move all the refPosition into output pool.
|
||||||
*/
|
*/
|
||||||
void moveAllToOutput() {
|
void moveAllToOutput() {
|
||||||
|
appendingFinished();
|
||||||
if (refPositions.empty()) {
|
if (refPositions.empty()) {
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
@ -496,9 +486,7 @@ public:
|
|||||||
Alignment newAlignment;
|
Alignment newAlignment;
|
||||||
|
|
||||||
|
|
||||||
while (true) {
|
while (linePool.recv(line)) {
|
||||||
std::unique_lock<std::mutex> lk{*workerLock[threadID]};
|
|
||||||
if (!linePool.recv(line)) break;
|
|
||||||
while (refPositions.empty()) {
|
while (refPositions.empty()) {
|
||||||
this_thread::sleep_for (std::chrono::microseconds(1));
|
this_thread::sleep_for (std::chrono::microseconds(1));
|
||||||
}
|
}
|
||||||
|
Loading…
Reference in New Issue
Block a user