226 |
|
private static int workerCountsFor(int t, int r) { return (t << 16) + r; } |
227 |
|
|
228 |
|
/** |
229 |
< |
* Add delta (which may be negative) to running count. This must |
229 |
> |
* Adds delta (which may be negative) to running count. This must |
230 |
|
* be called before (with negative arg) and after (with positive) |
231 |
< |
* any managed synchronization (i.e., mainly, joins) |
231 |
> |
* any managed synchronization (i.e., mainly, joins). |
232 |
|
* @param delta the number to add |
233 |
|
*/ |
234 |
|
final void updateRunningCount(int delta) { |
237 |
|
} |
238 |
|
|
239 |
|
/** |
240 |
< |
* Add delta (which may be negative) to both total and running |
240 |
> |
* Adds delta (which may be negative) to both total and running |
241 |
|
* count. This must be called upon creation and termination of |
242 |
|
* worker threads. |
243 |
|
* @param delta the number to add |
281 |
|
} |
282 |
|
|
283 |
|
/** |
284 |
< |
* Try decrementing active count; fail on contention. |
285 |
< |
* Possibly trigger termination on success |
284 |
> |
* Tries decrementing active count; fails on contention. |
285 |
> |
* Possibly triggers termination on success. |
286 |
|
* Called by workers when they can't find tasks. |
287 |
|
* @return true on success |
288 |
|
*/ |
297 |
|
} |
298 |
|
|
299 |
|
/** |
300 |
< |
* Return true if argument represents zero active count and |
300 |
> |
* Returns true if argument represents zero active count and |
301 |
|
* nonzero runstate, which is the triggering condition for |
302 |
|
* terminating on shutdown. |
303 |
|
*/ |
421 |
|
} |
422 |
|
|
423 |
|
/** |
424 |
< |
* Return a good size for worker array given pool size. |
424 |
> |
* Returns a good size for worker array given pool size. |
425 |
|
* Currently requires size to be a power of two. |
426 |
|
*/ |
427 |
|
private static int arraySizeFor(int ps) { |
429 |
|
} |
430 |
|
|
431 |
|
/** |
432 |
< |
* Create or resize array if necessary to hold newLength. |
433 |
< |
* Call only under exclusion or lock |
432 |
> |
* Creates or resizes array if necessary to hold newLength. |
433 |
> |
* Call only under exclusion or lock. |
434 |
|
* @return the array |
435 |
|
*/ |
436 |
|
private ForkJoinWorkerThread[] ensureWorkerArrayCapacity(int newLength) { |
1183 |
|
} |
1184 |
|
|
1185 |
|
/** |
1186 |
< |
* Possibly terminate when on shutdown state |
1186 |
> |
* Possibly terminates when on shutdown state. |
1187 |
|
*/ |
1188 |
|
private void terminateOnShutdown() { |
1189 |
|
if (!hasQueuedSubmissions() && canTerminateOnShutdown(runControl)) |
1191 |
|
} |
1192 |
|
|
1193 |
|
/** |
1194 |
< |
* Clear out and cancel submissions |
1194 |
> |
* Clears out and cancels submissions. |
1195 |
|
*/ |
1196 |
|
private void cancelQueuedSubmissions() { |
1197 |
|
ForkJoinTask<?> task; |
1200 |
|
} |
1201 |
|
|
1202 |
|
/** |
1203 |
< |
* Clean out worker queues. |
1203 |
> |
* Cleans out worker queues. |
1204 |
|
*/ |
1205 |
|
private void cancelQueuedWorkerTasks() { |
1206 |
|
final ReentrantLock lock = this.workerLock; |
1220 |
|
} |
1221 |
|
|
1222 |
|
/** |
1223 |
< |
* Set each worker's status to terminating. Requires lock to avoid |
1224 |
< |
* conflicts with add/remove |
1223 |
> |
* Sets each worker's status to terminating. Requires lock to avoid |
1224 |
> |
* conflicts with add/remove. |
1225 |
|
*/ |
1226 |
|
private void stopAllWorkers() { |
1227 |
|
final ReentrantLock lock = this.workerLock; |
1241 |
|
} |
1242 |
|
|
1243 |
|
/** |
1244 |
< |
* Interrupt all unterminated workers. This is not required for |
1244 |
> |
* Interrupts all unterminated workers. This is not required for |
1245 |
|
* sake of internal control, but may help unstick user code during |
1246 |
|
* shutdown. |
1247 |
|
*/ |
1311 |
|
} |
1312 |
|
|
1313 |
|
/** |
1314 |
< |
* Wake up waiter, returning false if known to already |
1314 |
> |
* Wakes up waiter, returning false if known to already |
1315 |
|
*/ |
1316 |
|
boolean signal() { |
1317 |
|
ForkJoinWorkerThread t = thread; |
1323 |
|
} |
1324 |
|
|
1325 |
|
/** |
1326 |
< |
* Await release on sync |
1326 |
> |
* Awaits release on sync. |
1327 |
|
*/ |
1328 |
|
void awaitSyncRelease(ForkJoinPool p) { |
1329 |
|
while (thread != null && !p.syncIsReleasable(this)) |
1331 |
|
} |
1332 |
|
|
1333 |
|
/** |
1334 |
< |
* Await resumption as spare |
1334 |
> |
* Awaits resumption as spare. |
1335 |
|
*/ |
1336 |
|
void awaitSpareRelease() { |
1337 |
|
while (thread != null) { |
1371 |
|
} |
1372 |
|
|
1373 |
|
/** |
1374 |
< |
* Signal threads waiting to poll a task. Because method sync |
1374 |
> |
* Signals threads waiting to poll a task. Because method sync |
1375 |
|
* rechecks availability, it is OK to only proceed if queue |
1376 |
|
* appears to be non-empty, and OK to skip under contention to |
1377 |
|
* increment count (since some other thread succeeded). |
1458 |
|
// Parallelism maintenance |
1459 |
|
|
1460 |
|
/** |
1461 |
< |
* Decrement running count; if too low, add spare. |
1461 |
> |
* Decrements running count; if too low, adds spare. |
1462 |
|
* |
1463 |
|
* Conceptually, all we need to do here is add or resume a |
1464 |
|
* spare thread when one is about to block (and remove or |
1548 |
|
} |
1549 |
|
|
1550 |
|
/** |
1551 |
< |
* Add a spare worker if lock available and no more than the |
1552 |
< |
* expected numbers of threads exist |
1551 |
> |
* Adds a spare worker if lock available and no more than the |
1552 |
> |
* expected numbers of threads exist. |
1553 |
|
* @return true if successful |
1554 |
|
*/ |
1555 |
|
private boolean tryAddSpare(int expectedCounts) { |
1582 |
|
} |
1583 |
|
|
1584 |
|
/** |
1585 |
< |
* Add the kth spare worker. On entry, pool counts are already |
1585 |
> |
* Adds the kth spare worker. On entry, pool counts are already |
1586 |
|
* adjusted to reflect addition. |
1587 |
|
*/ |
1588 |
|
private void createAndStartSpare(int k) { |
1604 |
|
} |
1605 |
|
|
1606 |
|
/** |
1607 |
< |
* Suspend calling thread w if there are excess threads. Called |
1608 |
< |
* only from sync. Spares are enqueued in a Treiber stack |
1609 |
< |
* using the same WaitQueueNodes as barriers. They are resumed |
1610 |
< |
* mainly in preJoin, but are also woken on pool events that |
1611 |
< |
* require all threads to check run state. |
1607 |
> |
* Suspends calling thread w if there are excess threads. Called |
1608 |
> |
* only from sync. Spares are enqueued in a Treiber stack using |
1609 |
> |
* the same WaitQueueNodes as barriers. They are resumed mainly |
1610 |
> |
* in preJoin, but are also woken on pool events that require all |
1611 |
> |
* threads to check run state. |
1612 |
|
* @param w the caller |
1613 |
|
*/ |
1614 |
|
private boolean suspendIfSpare(ForkJoinWorkerThread w) { |
1629 |
|
} |
1630 |
|
|
1631 |
|
/** |
1632 |
< |
* Try to pop and resume a spare thread. |
1632 |
> |
* Tries to pop and resume a spare thread. |
1633 |
|
* @param updateCount if true, increment running count on success |
1634 |
|
* @return true if successful |
1635 |
|
*/ |
1647 |
|
} |
1648 |
|
|
1649 |
|
/** |
1650 |
< |
* Pop and resume all spare threads. Same idea as ensureSync. |
1650 |
> |
* Pops and resumes all spare threads. Same idea as ensureSync. |
1651 |
|
* @return true if any spares released |
1652 |
|
*/ |
1653 |
|
private boolean resumeAllSpares() { |
1665 |
|
} |
1666 |
|
|
1667 |
|
/** |
1668 |
< |
* Pop and shutdown excessive spare threads. Call only while |
1668 |
> |
* Pops and shuts down excessive spare threads. Call only while |
1669 |
|
* holding lock. This is not guaranteed to eliminate all excess |
1670 |
|
* threads, only those suspended as spares, which are the ones |
1671 |
|
* unlikely to be needed in the future. |