private void maybeStop(long stopCheck, long now) { long delta = now - stopCheck; if (delta <= 0) { // if stopCheck has caught up with present, we've been spinning too much, so if we can atomically // set it to the past again, we should stop a worker if (pool.stopCheck.compareAndSet(stopCheck, now - stopCheckInterval)) { // try and stop ourselves; // if we've already been assigned work stop another worker if (!assign(Work.STOP_SIGNALLED, true)) pool.schedule(Work.STOP_SIGNALLED); } } else if (soleSpinnerSpinTime > stopCheckInterval && pool.spinningCount.get() == 1) { // permit self-stopping assign(Work.STOP_SIGNALLED, true); } else { // if stop check has gotten too far behind present, update it so new spins can affect it while (delta > stopCheckInterval * 2 && !pool.stopCheck.compareAndSet(stopCheck, now - stopCheckInterval)) { stopCheck = pool.stopCheck.get(); delta = now - stopCheck; } } }
private void maybeStop(long stopCheck, long now) { long delta = now - stopCheck; if (delta <= 0) { // if stopCheck has caught up with present, we've been spinning too much, so if we can atomically // set it to the past again, we should stop a worker if (pool.stopCheck.compareAndSet(stopCheck, now - stopCheckInterval)) { // try and stop ourselves; // if we've already been assigned work stop another worker if (!assign(Work.STOP_SIGNALLED, true)) pool.schedule(Work.STOP_SIGNALLED); } } else if (soleSpinnerSpinTime > stopCheckInterval && pool.spinningCount.get() == 1) { // permit self-stopping assign(Work.STOP_SIGNALLED, true); } else { // if stop check has gotten too far behind present, update it so new spins can affect it while (delta > stopCheckInterval * 2 && !pool.stopCheck.compareAndSet(stopCheck, now - stopCheckInterval)) { stopCheck = pool.stopCheck.get(); delta = now - stopCheck; } } }
private void maybeStop(long stopCheck, long now) { long delta = now - stopCheck; if (delta <= 0) { // if stopCheck has caught up with present, we've been spinning too much, so if we can atomically // set it to the past again, we should stop a worker if (pool.stopCheck.compareAndSet(stopCheck, now - stopCheckInterval)) { // try and stop ourselves; // if we've already been assigned work stop another worker if (!assign(Work.STOP_SIGNALLED, true)) pool.schedule(Work.STOP_SIGNALLED); } } else if (soleSpinnerSpinTime > stopCheckInterval && pool.spinningCount.get() == 1) { // permit self-stopping assign(Work.STOP_SIGNALLED, true); } else { // if stop check has gotten too far behind present, update it so new spins can affect it while (delta > stopCheckInterval * 2 && !pool.stopCheck.compareAndSet(stopCheck, now - stopCheckInterval)) { stopCheck = pool.stopCheck.get(); delta = now - stopCheck; } } }
private void maybeStop(long stopCheck, long now) { long delta = now - stopCheck; if (delta <= 0) { // if stopCheck has caught up with present, we've been spinning too much, so if we can atomically // set it to the past again, we should stop a worker if (pool.stopCheck.compareAndSet(stopCheck, now - stopCheckInterval)) { // try and stop ourselves; // if we've already been assigned work stop another worker if (!assign(Work.STOP_SIGNALLED, true)) pool.schedule(Work.STOP_SIGNALLED); } } else if (soleSpinnerSpinTime > stopCheckInterval && pool.spinningCount.get() == 1) { // permit self-stopping assign(Work.STOP_SIGNALLED, true); } else { // if stop check has gotten too far behind present, update it so new spins can affect it while (delta > stopCheckInterval * 2 && !pool.stopCheck.compareAndSet(stopCheck, now - stopCheckInterval)) { stopCheck = pool.stopCheck.get(); delta = now - stopCheck; } } }
void schedule(Work work) { // we try to hand-off our work to the spinning queue before the descheduled queue, even though we expect it to be empty // all we're doing here is hoping to find a worker without work to do, but it doesn't matter too much what we find; // we atomically set the task so even if this were a collection of all workers it would be safe, and if they are both // empty we schedule a new thread Map.Entry<Long, SEPWorker> e; while (null != (e = spinning.pollFirstEntry()) || null != (e = descheduled.pollFirstEntry())) if (e.getValue().assign(work, false)) return; if (!work.isStop()) new SEPWorker(workerId.incrementAndGet(), work, this); }
void schedule(Work work) { // we try to hand-off our work to the spinning queue before the descheduled queue, even though we expect it to be empty // all we're doing here is hoping to find a worker without work to do, but it doesn't matter too much what we find; // we atomically set the task so even if this were a collection of all workers it would be safe, and if they are both // empty we schedule a new thread Map.Entry<Long, SEPWorker> e; while (null != (e = spinning.pollFirstEntry()) || null != (e = descheduled.pollFirstEntry())) if (e.getValue().assign(work, false)) return; if (!work.isStop()) new SEPWorker(workerId.incrementAndGet(), work, this); }
void schedule(Work work) { // we try to hand-off our work to the spinning queue before the descheduled queue, even though we expect it to be empty // all we're doing here is hoping to find a worker without work to do, but it doesn't matter too much what we find; // we atomically set the task so even if this were a collection of all workers it would be safe, and if they are both // empty we schedule a new thread Map.Entry<Long, SEPWorker> e; while (null != (e = spinning.pollFirstEntry()) || null != (e = descheduled.pollFirstEntry())) if (e.getValue().assign(work, false)) return; if (!work.isStop()) new SEPWorker(workerId.incrementAndGet(), work, this); }
void schedule(Work work) { // we try to hand-off our work to the spinning queue before the descheduled queue, even though we expect it to be empty // all we're doing here is hoping to find a worker without work to do, but it doesn't matter too much what we find; // we atomically set the task so even if this were a collection of all workers it would be safe, and if they are both // empty we schedule a new thread Map.Entry<Long, SEPWorker> e; while (null != (e = spinning.pollFirstEntry()) || null != (e = descheduled.pollFirstEntry())) if (e.getValue().assign(work, false)) return; if (!work.isStop()) new SEPWorker(workerId.incrementAndGet(), work, this); }
private boolean selfAssign() { // if we aren't permitted to assign in this state, fail if (!get().canAssign(true)) return false; for (SEPExecutor exec : pool.executors) { if (exec.takeWorkPermit(true)) { Work work = new Work(exec); // we successfully started work on this executor, so we must either assign it to ourselves or ... if (assign(work, true)) return true; // ... if we fail, schedule it to another worker pool.schedule(work); // and return success as we must have already been assigned a task assert get().assigned != null; return true; } } return false; }
private boolean selfAssign() { // if we aren't permitted to assign in this state, fail if (!get().canAssign(true)) return false; for (SEPExecutor exec : pool.executors) { if (exec.takeWorkPermit(true)) { Work work = new Work(exec); // we successfully started work on this executor, so we must either assign it to ourselves or ... if (assign(work, true)) return true; // ... if we fail, schedule it to another worker pool.schedule(work); // and return success as we must have already been assigned a task assert get().assigned != null; return true; } } return false; }
private boolean selfAssign() { // if we aren't permitted to assign in this state, fail if (!get().canAssign(true)) return false; for (SEPExecutor exec : pool.executors) { if (exec.takeWorkPermit(true)) { Work work = new Work(exec); // we successfully started work on this executor, so we must either assign it to ourselves or ... if (assign(work, true)) return true; // ... if we fail, schedule it to another worker pool.schedule(work); // and return success as we must have already been assigned a task assert get().assigned != null; return true; } } return false; }
private boolean selfAssign() { // if we aren't permitted to assign in this state, fail if (!get().canAssign(true)) return false; for (SEPExecutor exec : pool.executors) { if (exec.takeWorkPermit(true)) { Work work = new Work(exec); // we successfully started work on this executor, so we must either assign it to ourselves or ... if (assign(work, true)) return true; // ... if we fail, schedule it to another worker pool.schedule(work); // and return success as we must have already been assigned a task assert get().assigned != null; return true; } } return false; }
set(Work.WORKING); if (assign(Work.STOPPED, true)) break;
set(Work.WORKING); if (assign(Work.STOPPED, true)) break;
set(Work.WORKING); if (assign(Work.STOPPED, true)) break;
set(Work.WORKING); if (assign(Work.STOPPED, true)) break;