-
-
Notifications
You must be signed in to change notification settings - Fork 161
Rwlock #181
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Rwlock #181
Conversation
kernel/src/libs/rwlock.rs
Outdated
#[inline] | ||
/// @brief 获取实时的读者数并尝试加1,如果增加值成功则返回增加1后的读者数,否则panic | ||
fn current_reader(&self) -> Result<u32, u32> { | ||
const MAX_READERS: u32 = core::u32::MAX / READER / 2; //右移3位 |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
歧义,加括号。
然后,所有用乘除法实现的位运算功能,直接改为位运算即可。
kernel/src/libs/rwlock.rs
Outdated
/// @brief 获取读者+UPGRADER的数量, 不能保证能否获得同步值 | ||
pub fn reader_count(&self) -> u32 { | ||
let state = self.lock.load(Ordering::Relaxed); | ||
state / READER + (state & UPGRADED) / UPGRADED |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
kernel/src/libs/rwlock.rs
Outdated
/// @brief 尝试获得UPGRADER守卫 | ||
pub fn try_upgradeable_read(&self) -> Option<RwLockUpgradableGuard<T>> { | ||
//获得UPGRADER守卫不需要查看读者位 | ||
//如果获得读者锁失败,不撤回fetch_or的原子操作 |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
为什么
kernel/src/libs/rwlock.rs
Outdated
#[inline] | ||
pub fn downgrade(self) -> RwLockReadGuard<'rwlock, T> { | ||
while { | ||
let res = self.inner.current_reader(); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
这里不需要写成闭包,一句话写好即可
No description provided.