int oldVal, newVal;
do {
oldVal = state;
if (writeIntended && allAreSet(oldVal, FLAG_IN_WRITE)) {
// concurrent writers are an error
throw new ConcurrentStreamChannelAccessException();
}
if (anyAreSet(oldVal, skipIfSet) || anyAreClear(oldVal, skipIfClear)) {
return oldVal;
}
while (anyAreSet(oldVal, FLAG_IN | FLAG_IN_WRITE)) {