jdk-17, StampedLock, 修改写锁计数有内存屏障,为什么修改读锁计数时没有?
是因为使用或操作吗?
@ReservedStackAccess private long tryAcquireWrite() {
long s, nextState;
if (((s = state) & ABITS) == 0L && casState(s, nextState = s | WBIT)) {
// ?
U.storeStoreFence();
return nextState;
}
return 0L;
}
@ReservedStackAccess
private long tryAcquireRead() {
for (long s, m, nextState;;) {
if ((m = (s = state) & ABITS) < RFULL) {
if (casState(s, nextState = s + RUNIT))
// ?
return nextState;
}
else if (m == WBIT)
return 0L;
else if ((nextState = tryIncReaderOverflow(s)) != 0L)
return nextState;
}
}
public long writeLock() {
// try unconditional CAS confirming weak read
long s = U.getLongOpaque(this, STATE) & ~ABITS, nextState;
if (casState(s, nextState = s | WBIT)) {
// ?
U.storeStoreFence();
return nextState;
}
return acquireWrite(false, false, 0L);
}
public long readLock() {
// unconditionally optimistically try non-overflow case once
long s = U.getLongOpaque(this, STATE) & RSAFE, nextState;
if (casState(s, nextState = s + RUNIT))
// ?
return nextState;
else
return acquireRead(false, false, 0L);
}
以上是 jdk-17, StampedLock, 修改写锁计数有内存屏障,为什么修改读锁计数时没有? 的全部内容, 来源链接: utcz.com/p/944451.html