Fix threaded sam_read1 after EOF. #1856
Merged
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
The SAM sam_dispatcher_read decodes blocks of SAM records into blocks of BAM records. As this is (hopefully) reading ahead of the sam_read1 consumer code, when it hits EOF it adds a final NULL block as a sentinel. This works well and it forces sam_read1 to return EOF too.
However, if we ignore that and call sam_read1 again, it's consumed our sentinel block and it gets stuck waiting for the next block of BAM records. We now cache the EOF status and check first.
Note this doesn't impact on iterators as they work at a different level already and it's the iterator itself which tracks EOF.
Fixes #1855