Add 'pread'-backed method for thread-safe hunk reading#162
Open
xakep666 wants to merge 1 commit into
Open
Conversation
9a1137d to
160f6af
Compare
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
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.
Addressing proposal in #34
This PR adds method
chd_read_threadsafe- a thread-safe version ofchd_read. This method will be helpful for implementing threaded read-aheads purely by consumers without adding external dependencies (likepthread) .My main programming language is Go and there's a popular approach "leave concurrency to a caller" used when concurrent code is written. And I think it fits good in this case.
Some implementation details:
chd_read_threadsafemethod has extra argumentcompressed_bufferwhich is used to store raw compressed data read from file. This is the one of two things required for thread-safety.chd_readuses same buffer stored inchd_filestructure.fpreadadded tochd_core_file_callbacksto allow thread-safe reading from file. Used only inchd_read_threadsafe.fpreadwas not providedchd_read_threadsafewill return errorCHDERR_NOT_SUPPORTED.hunk_read_into_memoryhas been tweaked a bit to accept arbitrary compressed data buffer pointer and different reading methods:seek_and_read(old one) orread_at(new one).chd->compressedas it only used insidechd_read.