uses pthreads over spinlocks and also little revise of structures used in the code #638
+77
−77
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.
little overview of what i changed and explanation of used structured within the code :
uses pthreads mutexes instead of spinlocks to synchronize access to the buffer cache and individual buffers. also removes the
sleeplock
functionality and replaces it with simple mutexes for simplicity.bget
function returnsNULL
if no buffer is available rather than panicking.bread
function returnsNULL
if the read from the disk fails or if no buffer is available.bwrite
function returns a boolean indicating whether the write to the disk was successful.brelse
function no longer takes a spinlock on the buffer cache before releasing the buffer lock.buf structure gonna represents a buffer in the buffer cache. It stores the device and block number of the block that the buffer holds, a flag indicating whether the buffer's data is valid anda reference count indicating how many users have a reference to the buffer
buf_cache structure represents the buffer cache stores an array of buf structures act as a linked list of buffers sorted by how recently they were used.
buf_cache_init function initializes the buffer cache by initializing the mutex and creating the linked list of buffers.
hope to help ..