Skip to content

Commit

Permalink
bug fix for buffer queue
Browse files Browse the repository at this point in the history
  • Loading branch information
sfchen committed May 16, 2018
1 parent 71f57b3 commit 00301cc
Show file tree
Hide file tree
Showing 3 changed files with 11 additions and 13 deletions.
2 changes: 1 addition & 1 deletion src/common.h
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,7 @@ typedef unsigned char uint8;

// the limit of the queue to store the packs
// error may happen if it generates more packs than this number
static const int PACK_NUM_LIMIT = 1000000;
static const int PACK_NUM_LIMIT = 5000000;

// how many reads one pack has
static const int PACK_SIZE = 1000;
Expand Down
11 changes: 5 additions & 6 deletions src/pescanner.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -237,7 +237,7 @@ void PairEndScanner::consumePack(){
ReadPairPack* data;
std::unique_lock<std::mutex> lock(mRepo.mtx);
// read buffer is empty, just wait here.
while(mRepo.writePos == mRepo.readPos) {
while(mRepo.writePos % PACK_NUM_LIMIT == mRepo.readPos % PACK_NUM_LIMIT) {
if(mProduceFinished){
lock.unlock();
return;
Expand All @@ -246,16 +246,15 @@ void PairEndScanner::consumePack(){
}

data = mRepo.packBuffer[mRepo.readPos];
(mRepo.readPos)++;
lock.unlock();

scanPairEnd(data);

mRepo.readPos++;

if (mRepo.readPos >= PACK_NUM_LIMIT)
mRepo.readPos = 0;

lock.unlock();
mRepo.repoNotFull.notify_all();

scanPairEnd(data);
}

void PairEndScanner::producerTask()
Expand Down
11 changes: 5 additions & 6 deletions src/sescanner.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -206,7 +206,7 @@ void SingleEndScanner::consumePack(){
ReadPack* data;
std::unique_lock<std::mutex> lock(mRepo.mtx);
// read buffer is empty, just wait here.
while(mRepo.writePos == mRepo.readPos) {
while(mRepo.writePos % PACK_NUM_LIMIT == mRepo.readPos % PACK_NUM_LIMIT) {
if(mProduceFinished){
lock.unlock();
return;
Expand All @@ -215,16 +215,15 @@ void SingleEndScanner::consumePack(){
}

data = mRepo.packBuffer[mRepo.readPos];
(mRepo.readPos)++;
lock.unlock();

scanSingleEnd(data);

mRepo.readPos++;

if (mRepo.readPos >= PACK_NUM_LIMIT)
mRepo.readPos = 0;

lock.unlock();
mRepo.repoNotFull.notify_all();

scanSingleEnd(data);
}

void SingleEndScanner::producerTask()
Expand Down

0 comments on commit 00301cc

Please sign in to comment.