/** * @param lock Lock address. */ public void writeUnlock(long lock, int tag) { long updated; assert tag != 0; while (true) { long state = GridUnsafe.getLongVolatile(null, lock); if (lockCount(state) != -1) throw new IllegalMonitorStateException("Attempted to release write lock while not holding it " + "[lock=" + U.hexLong(lock) + ", state=" + U.hexLong(state) + ']'); updated = releaseWithTag(state, tag); assert updated != 0; if (GridUnsafe.compareAndSwapLong(null, lock, state, updated)) break; } int writeWaitCnt = writersWaitCount(updated); int readWaitCnt = readersWaitCount(updated); if (writeWaitCnt > 0 || readWaitCnt > 0) { int idx = lockIndex(lock); ReentrantLock lockObj = locks[idx]; lockObj.lock(); try { signalNextWaiter(writeWaitCnt, readWaitCnt, idx); } finally { lockObj.unlock(); } } }
int readWaitCnt = readersWaitCount(updated); signalNextWaiter(writeWaitCnt, readWaitCnt, lockIdx);
int readWaitCnt = readersWaitCount(updated); signalNextWaiter(writeWaitCnt, readWaitCnt, lockIdx);
/** * @param lock Lock address. */ public void writeUnlock(long lock, int tag) { long updated; assert tag != 0; while (true) { long state = GridUnsafe.getLongVolatile(null, lock); if (lockCount(state) != -1) throw new IllegalMonitorStateException("Attempted to release write lock while not holding it " + "[lock=" + U.hexLong(lock) + ", state=" + U.hexLong(state)); updated = releaseWithTag(state, tag); assert updated != 0; if (GridUnsafe.compareAndSwapLong(null, lock, state, updated)) break; } int writeWaitCnt = writersWaitCount(updated); int readWaitCnt = readersWaitCount(updated); if (writeWaitCnt > 0 || readWaitCnt > 0) { int idx = lockIndex(lock); ReentrantLock lockObj = locks[idx]; lockObj.lock(); try { signalNextWaiter(writeWaitCnt, readWaitCnt, idx); } finally { lockObj.unlock(); } } }
int readWaitCnt = readersWaitCount(updated); signalNextWaiter(writeWaitCnt, readWaitCnt, lockIdx);
int readWaitCnt = readersWaitCount(updated); signalNextWaiter(writeWaitCnt, readWaitCnt, lockIdx);