Skip to content

Commit 00301cc

Browse files
committed
bug fix for buffer queue
1 parent 71f57b3 commit 00301cc

File tree

3 files changed

+11
-13
lines changed

3 files changed

+11
-13
lines changed

src/common.h

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -22,7 +22,7 @@ typedef unsigned char uint8;
2222

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

2727
// how many reads one pack has
2828
static const int PACK_SIZE = 1000;

src/pescanner.cpp

Lines changed: 5 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -237,7 +237,7 @@ void PairEndScanner::consumePack(){
237237
ReadPairPack* data;
238238
std::unique_lock<std::mutex> lock(mRepo.mtx);
239239
// read buffer is empty, just wait here.
240-
while(mRepo.writePos == mRepo.readPos) {
240+
while(mRepo.writePos % PACK_NUM_LIMIT == mRepo.readPos % PACK_NUM_LIMIT) {
241241
if(mProduceFinished){
242242
lock.unlock();
243243
return;
@@ -246,16 +246,15 @@ void PairEndScanner::consumePack(){
246246
}
247247

248248
data = mRepo.packBuffer[mRepo.readPos];
249-
(mRepo.readPos)++;
250-
lock.unlock();
251-
252-
scanPairEnd(data);
253-
249+
mRepo.readPos++;
254250

255251
if (mRepo.readPos >= PACK_NUM_LIMIT)
256252
mRepo.readPos = 0;
257253

254+
lock.unlock();
258255
mRepo.repoNotFull.notify_all();
256+
257+
scanPairEnd(data);
259258
}
260259

261260
void PairEndScanner::producerTask()

src/sescanner.cpp

Lines changed: 5 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -206,7 +206,7 @@ void SingleEndScanner::consumePack(){
206206
ReadPack* data;
207207
std::unique_lock<std::mutex> lock(mRepo.mtx);
208208
// read buffer is empty, just wait here.
209-
while(mRepo.writePos == mRepo.readPos) {
209+
while(mRepo.writePos % PACK_NUM_LIMIT == mRepo.readPos % PACK_NUM_LIMIT) {
210210
if(mProduceFinished){
211211
lock.unlock();
212212
return;
@@ -215,16 +215,15 @@ void SingleEndScanner::consumePack(){
215215
}
216216

217217
data = mRepo.packBuffer[mRepo.readPos];
218-
(mRepo.readPos)++;
219-
lock.unlock();
220-
221-
scanSingleEnd(data);
222-
218+
mRepo.readPos++;
223219

224220
if (mRepo.readPos >= PACK_NUM_LIMIT)
225221
mRepo.readPos = 0;
226222

223+
lock.unlock();
227224
mRepo.repoNotFull.notify_all();
225+
226+
scanSingleEnd(data);
228227
}
229228

230229
void SingleEndScanner::producerTask()

0 commit comments

Comments
 (0)