/** * @param state State. * @param tag Tag. */ private boolean checkTag(long state, int tag) { // If passed in tag is negative, lock regardless of the state. return tag < 0 || tag(state) == tag; }
/** * @param state State to update. * @param lockDelta Lock counter delta. * @param readersWaitDelta Readers wait delta. * @param writersWaitDelta Writers wait delta. * @return Modified state. */ private long updateState(long state, int lockDelta, int readersWaitDelta, int writersWaitDelta) { int lock = lockCount(state); int tag = tag(state); int readersWait = readersWaitCount(state); int writersWait = writersWaitCount(state); lock += lockDelta; readersWait += readersWaitDelta; writersWait += writersWaitDelta; if (readersWait > MAX_WAITERS) throw new IllegalStateException("Failed to add read waiter (too many waiting threads): " + MAX_WAITERS); if (writersWait > MAX_WAITERS) throw new IllegalStateException("Failed to add write waiter (too many waiting threads): " + MAX_WAITERS); assert readersWait >= 0 : readersWait; assert writersWait >= 0 : writersWait; assert lock >= -1; return buildState(writersWait, readersWait, tag, lock); }
/** * @param state State to update. * @return Modified state. */ private long releaseWithTag(long state, int newTag) { int lock = lockCount(state); int readersWait = readersWaitCount(state); int writersWait = writersWaitCount(state); int tag = newTag == TAG_LOCK_ALWAYS ? tag(state) : newTag & 0xFFFF; lock += 1; assert readersWait >= 0 : readersWait; assert writersWait >= 0 : writersWait; assert lock >= -1; return buildState(writersWait, readersWait, tag, lock); }
/** * @param state State. * @param tag Tag. */ private boolean checkTag(long state, int tag) { // If passed in tag is negative, lock regardless of the state. return tag < 0 || tag(state) == tag; }
/** * @param state State to update. * @param lockDelta Lock counter delta. * @param readersWaitDelta Readers wait delta. * @param writersWaitDelta Writers wait delta. * @return Modified state. */ private long updateState(long state, int lockDelta, int readersWaitDelta, int writersWaitDelta) { int lock = lockCount(state); int tag = tag(state); int readersWait = readersWaitCount(state); int writersWait = writersWaitCount(state); lock += lockDelta; readersWait += readersWaitDelta; writersWait += writersWaitDelta; if (readersWait > MAX_WAITERS) throw new IllegalStateException("Failed to add read waiter (too many waiting threads): " + MAX_WAITERS); if (writersWait > MAX_WAITERS) throw new IllegalStateException("Failed to add write waiter (too many waiting threads): " + MAX_WAITERS); assert readersWait >= 0 : readersWait; assert writersWait >= 0 : writersWait; assert lock >= -1; return buildState(writersWait, readersWait, tag, lock); }
/** * @param state State to update. * @return Modified state. */ private long releaseWithTag(long state, int newTag) { int lock = lockCount(state); int readersWait = readersWaitCount(state); int writersWait = writersWaitCount(state); int tag = newTag == TAG_LOCK_ALWAYS ? tag(state) : newTag & 0xFFFF; lock += 1; assert readersWait >= 0 : readersWait; assert writersWait >= 0 : writersWait; assert lock >= -1; return buildState(writersWait, readersWait, tag, lock); }