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); }
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; }
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 stop() { return get().isStop() && compareAndSet(Work.STOP_SIGNALLED, Work.STOPPED); }
private boolean stop() { return get().isStop() && compareAndSet(Work.STOP_SIGNALLED, Work.STOPPED); }
private boolean stop() { return get().isStop() && compareAndSet(Work.STOP_SIGNALLED, Work.STOPPED); }
private boolean stop() { return get().isStop() && compareAndSet(Work.STOP_SIGNALLED, Work.STOPPED); }