From 00301cc42d6cb66a11eecef9fd1005edb7885881 Mon Sep 17 00:00:00 2001 From: Shifu Chen Date: Wed, 16 May 2018 16:14:14 +0800 Subject: [PATCH] bug fix for buffer queue --- src/common.h | 2 +- src/pescanner.cpp | 11 +++++------ src/sescanner.cpp | 11 +++++------ 3 files changed, 11 insertions(+), 13 deletions(-) diff --git a/src/common.h b/src/common.h index 9cb994d..d50bf86 100644 --- a/src/common.h +++ b/src/common.h @@ -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; diff --git a/src/pescanner.cpp b/src/pescanner.cpp index 910c70f..d684a7b 100644 --- a/src/pescanner.cpp +++ b/src/pescanner.cpp @@ -237,7 +237,7 @@ void PairEndScanner::consumePack(){ ReadPairPack* data; std::unique_lock 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; @@ -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() diff --git a/src/sescanner.cpp b/src/sescanner.cpp index 21b0c67..a42deda 100644 --- a/src/sescanner.cpp +++ b/src/sescanner.cpp @@ -206,7 +206,7 @@ void SingleEndScanner::consumePack(){ ReadPack* data; std::unique_lock 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; @@ -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()