Created
October 30, 2017 20:29
-
-
Save OlegDokuka/d2b7262e77e0ad782404bd8a6239ccc2 to your computer and use it in GitHub Desktop.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| for (;;) { | |
| long currentDemand = demand.getAcquire(); // (1) | |
| if (currentDemand == Long.MAX_VALUE) { // (2) | |
| return; | |
| } | |
| long adjustedDemand = currentDemand + n; | |
| if (adjustedDemand < 0L) { // (3) | |
| adjustedDemand = Long.MAX_VALUE; | |
| } | |
| if (demand.compareAndSet(currentDemand, adjustedDemand)) { // (4) | |
| if (currentDemand > 0) { // (5) | |
| return; | |
| } | |
| break; | |
| } | |
| } |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment