1668 |
|
* @param ec the worker's eventCount on entry to scan |
1669 |
|
*/ |
1670 |
|
private final int awaitWork(WorkQueue w, long c, int ec) { |
1671 |
< |
int stat = 0; |
1672 |
< |
if (w != null && w.eventCount == ec && ctl == c) { |
1673 |
< |
int ns; |
1671 |
> |
int stat, ns; long parkTime, deadline; |
1672 |
> |
if ((stat = w.qlock) >= 0 && w.eventCount == ec && ctl == c && |
1673 |
> |
!Thread.interrupted()) { |
1674 |
|
int e = (int)c; |
1675 |
|
int u = (int)(c >>> 32); |
1676 |
|
int d = (u >> UAC_SHIFT) + (config & SMASK); // 0 if quiescent |
1677 |
|
|
1678 |
|
if (e < 0 || (d == 0 && tryTerminate(false, false))) |
1679 |
< |
w.qlock = stat = -1; // pool is terminating |
1680 |
< |
else if ((ns = w.nsteals) != 0) { |
1681 |
< |
long sc = stealCount; // collect steals |
1682 |
< |
if (U.compareAndSwapLong(this, STEALCOUNT, sc, sc + ns)) |
1683 |
< |
w.nsteals = 0; |
1679 |
> |
stat = w.qlock = -1; // pool is terminating |
1680 |
> |
else if ((ns = w.nsteals) != 0) { // collect steals and retry |
1681 |
> |
w.nsteals = 0; |
1682 |
> |
U.getAndAddLong(this, STEALCOUNT, (long)ns); |
1683 |
|
} |
1684 |
< |
else if (!Thread.interrupted()) { |
1686 |
< |
long parkTime, deadline; |
1684 |
> |
else { |
1685 |
|
long pc = ((d != 0 || ec != (e | INT_SIGN)) ? 0L : |
1686 |
|
((long)(w.nextWait & E_MASK)) | // ctl to restore |
1687 |
|
((long)(u + UAC_UNIT)) << 32); |
1688 |
< |
if (pc != 0L) { // timed wait if last waiter |
1688 |
> |
if (pc != 0L) { // timed wait if last waiter |
1689 |
|
int dc = -(short)(c >>> TC_SHIFT); |
1690 |
|
parkTime = (dc < 0 ? FAST_IDLE_TIMEOUT: |
1691 |
|
(dc + 1) * IDLE_TIMEOUT); |
1696 |
|
if (w.eventCount == ec && ctl == c) { |
1697 |
|
Thread wt = Thread.currentThread(); |
1698 |
|
U.putObject(wt, PARKBLOCKER, this); |
1699 |
< |
w.parker = wt; // emulate LockSupport.park |
1699 |
> |
w.parker = wt; // emulate LockSupport.park |
1700 |
|
if (w.eventCount == ec && ctl == c) |
1701 |
|
U.park(false, parkTime); // must recheck before park |
1702 |
|
w.parker = null; |
1704 |
|
if (parkTime != 0L && ctl == c && |
1705 |
|
deadline - System.nanoTime() <= 0L && |
1706 |
|
U.compareAndSwapLong(this, CTL, c, pc)) |
1707 |
< |
w.qlock = stat = -1; // shrink pool |
1707 |
> |
stat = w.qlock = -1; // shrink pool |
1708 |
|
} |
1709 |
|
} |
1710 |
|
} |