boolean assign(Work work, boolean self) { Work state = get(); while (state.canAssign(self)) { if (!compareAndSet(state, work)) { state = get(); continue; } // if we were spinning, exit the state (decrement the count); this is valid even if we are already spinning, // as the assigning thread will have incremented the spinningCount if (state.isSpinning()) stopSpinning(); // if we're being descheduled, place ourselves in the descheduled collection if (work.isStop()) pool.descheduled.put(workerId, this); // if we're currently stopped, and the new state is not a stop signal // (which we can immediately convert to stopped), unpark the worker if (state.isStopped() && (!work.isStop() || !stop())) LockSupport.unpark(thread); return true; } return false; }
boolean assign(Work work, boolean self) { Work state = get(); while (state.canAssign(self)) { if (!compareAndSet(state, work)) { state = get(); continue; } // if we were spinning, exit the state (decrement the count); this is valid even if we are already spinning, // as the assigning thread will have incremented the spinningCount if (state.isSpinning()) stopSpinning(); // if we're being descheduled, place ourselves in the descheduled collection if (work.isStop()) pool.descheduled.put(workerId, this); // if we're currently stopped, and the new state is not a stop signal // (which we can immediately convert to stopped), unpark the worker if (state.isStopped() && (!work.isStop() || !stop())) LockSupport.unpark(thread); return true; } return false; }
boolean assign(Work work, boolean self) { Work state = get(); while (state.canAssign(self)) { if (!compareAndSet(state, work)) { state = get(); continue; } // if we were spinning, exit the state (decrement the count); this is valid even if we are already spinning, // as the assigning thread will have incremented the spinningCount if (state.isSpinning()) stopSpinning(); // if we're being descheduled, place ourselves in the descheduled collection if (work.isStop()) pool.descheduled.put(workerId, this); // if we're currently stopped, and the new state is not a stop signal // (which we can immediately convert to stopped), unpark the worker if (state.isStopped() && (!work.isStop() || !stop())) LockSupport.unpark(thread); return true; } return false; }
boolean assign(Work work, boolean self) { Work state = get(); while (state.canAssign(self)) { if (!compareAndSet(state, work)) { state = get(); continue; } // if we were spinning, exit the state (decrement the count); this is valid even if we are already spinning, // as the assigning thread will have incremented the spinningCount if (state.isSpinning()) stopSpinning(); // if we're being descheduled, place ourselves in the descheduled collection if (work.isStop()) pool.descheduled.put(workerId, this); // if we're currently stopped, and the new state is not a stop signal // (which we can immediately convert to stopped), unpark the worker if (state.isStopped() && (!work.isStop() || !stop())) LockSupport.unpark(thread); 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; }
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; }