有关读流程代码的一些疑问 #5390
Lawliet828
started this conversation in
General
有关读流程代码的一些疑问
#5390
Replies: 1 comment
-
|
Beta Was this translation helpful? Give feedback.
0 replies
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
-
1
readAhead函数
无论是否进入 if r.state == READY 分支,block.len 最终都会被重新设置,要不
block.len = block.end() - r.block.end()
要不block.len = 0
,这使得block.len -= f.r.blockSize / 2
的操作没有实际效果,所以红框中的代码是无效代码吧。2
run函数
162行
f.Lock()
后,163行defer f.Unlock()
,然后170行f.Unlock()
,会让人比较迷惑,因为double unlock会引发运行时错误。实际上162行
f.Lock()
和170行f.Unlock()
是一对,174行f.Lock()
和200行f.Unlock()
是一对,163行的defer f.Unlock()
应该与208行f.Lock()
配对使用,所以defer f.Unlock()
移到208行之后更合理。Beta Was this translation helpful? Give feedback.
All reactions