Skip to content

Commit

Permalink
refactored
Browse files Browse the repository at this point in the history
  • Loading branch information
Anthony4m committed Dec 26, 2024
1 parent 4374af1 commit 9fbd5df
Showing 1 changed file with 16 additions and 4 deletions.
20 changes: 16 additions & 4 deletions buffer/bufferMgr.go
Original file line number Diff line number Diff line change
Expand Up @@ -110,22 +110,34 @@ func (bM *BufferMgr) pin(blk *kfile.BlockId) (*Buffer, error) {
for buff == nil && !bM.waitingTooLong(starttime) {
timer := time.NewTimer(MAX_TIME)
waiting := make(chan struct{})
done := make(chan struct{})

go func() {
bM.cond.L.Lock()
defer bM.cond.L.Unlock()
bM.cond.Wait()
close(waiting)

select {
case <-done:
return
default:
bM.cond.Wait()
select {
case <-done:
default:
close(waiting)
}
}
}()

select {
case <-waiting:

timer.Stop()
close(done)
case <-timer.C:
close(done)
return nil, fmt.Errorf("BufferAbortException: No buffers available after waiting %v", MAX_TIME)
}

timer.Stop()
buff = bM.Get(blk)
if buff == nil && bM.numAvailable > 0 {
buff = bM.Insert(blk)
Expand Down

0 comments on commit 9fbd5df

Please sign in to comment.