摘要: private final ReentrantLock lock = new ReentrantLock(); private static class Generation { Generation() {} boolean broken; } private Generation generat 阅读全文
posted @ 2021-05-28 10:52 榆木脑袋0v0 阅读(74) 评论(0) 推荐(0) 编辑
摘要: @ReservedStackAccess final boolean tryReadLock() { Thread current = Thread.currentThread(); // 死循环 for (;;) { int c = getState(); // 当前有别的线程持有写锁,此时尝试获 阅读全文
posted @ 2021-05-20 21:01 榆木脑袋0v0 阅读(47) 评论(0) 推荐(0) 编辑
摘要: static final class ThreadLocalHoldCounter extends ThreadLocal<HoldCounter> { public HoldCounter initialValue() { return new HoldCounter(); } } private 阅读全文
posted @ 2021-05-19 13:28 榆木脑袋0v0 阅读(343) 评论(0) 推荐(0) 编辑
摘要: static final class ThreadLocalHoldCounter extends ThreadLocal<HoldCounter> { public HoldCounter initialValue() { return new HoldCounter(); } } private 阅读全文
posted @ 2021-05-18 14:05 榆木脑袋0v0 阅读(136) 评论(0) 推荐(0) 编辑
摘要: // 尝试获取写锁 protected final boolean tryAcquire(int acquires) { Thread current = Thread.currentThread(); int c = getState(); // 全状态 int w = exclusiveCoun 阅读全文
posted @ 2021-05-17 17:09 榆木脑袋0v0 阅读(47) 评论(0) 推荐(0) 编辑
摘要: ReentrantReadWriteLock.Sync的状态为一个32位整数。分为两部分,每部分16位,1~16位为写锁的重入次数,17~32位为读锁的获取次数。 阅读全文
posted @ 2021-05-17 16:50 榆木脑袋0v0 阅读(44) 评论(0) 推荐(0) 编辑
摘要: // ReentrantLock.FairSync::initialTryLock final boolean initialTryLock() { Thread current = Thread.currentThread(); int c = getState(); // c==0说明当前锁无人 阅读全文
posted @ 2021-05-06 14:38 榆木脑袋0v0 阅读(66) 评论(0) 推荐(0) 编辑
摘要: // 尝试释放锁 protected final boolean tryRelease(int releases) { // c:释放锁后的新state int c = getState() - releases; if (getExclusiveOwnerThread() != Thread.cu 阅读全文
posted @ 2021-05-06 14:25 榆木脑袋0v0 阅读(50) 评论(0) 推荐(0) 编辑
摘要: // 尝试获取锁 // 尝试获取成功返回true // 尝试获取失败返回false final boolean tryLock() { Thread current = Thread.currentThread(); int c = getState(); // c == 0 说明当前锁处于闲置状态 阅读全文
posted @ 2021-04-26 15:09 榆木脑袋0v0 阅读(48) 评论(0) 推荐(0) 编辑
摘要: /** * Unlinks the given node and other non-waiting nodes from * condition queue unless already unlinked. */ private void unlinkCancelledWaiters(Condit 阅读全文
posted @ 2021-04-23 22:05 榆木脑袋0v0 阅读(110) 评论(0) 推荐(0) 编辑