int (final int tokensToAdd) { assert tokensToAdd >= 0 : "tokensToAdd(" + tokensToAdd + ") must be >=0"; while (true) {//CAS loop: final int tokens = tokensOfUsefulness; int newTokens = tokens + tokensToAdd; if (newTokens < 0) {//protect from overflow newTokens = Integer.MAX_VALUE; } if (TOKENS_UPDATER.compareAndSet(this, tokens, newTokens)) { return newTokens; } } }