static Strand get(Thread t) { Strand s = threadStrands.get(t.getId()); if (s == null) { s = new ThreadStrand(t); Strand p = threadStrands.putIfAbsent(t.getId(), s); if (p != null) s = p; // else { // final Runnable target = ThreadAccess.getTarget(t); // if (target != null && target instanceof Stranded) // ((Stranded) target).setStrand(s); // } } return s; }
/** * Returns the current strand. * This method will return a strand representing the fiber calling this method, or the current thread if this method is not * called within a fiber. * * @return A strand representing the current fiber or thread */ public static Strand currentStrand() { if (FiberForkJoinScheduler.isFiberThread(Thread.currentThread())) return Fiber.currentFiber(); Strand s = currentStrand.get(); if (s == null) { s = ThreadStrand.get(Thread.currentThread()); currentStrand.set(s); } return s; // final Fiber fiber = Fiber.currentFiber(); // if (fiber != null) // return of(fiber); // else // return ThreadStrand.currStrand(); }
public static Strand create(Thread owner) { return new ThreadStrand(owner); }
public static Strand clone(Strand strand, final SuspendableRunnable target) { if (strand.isAlive()) throw new IllegalStateException("A strand can only be cloned after death. " + strand + " isn't dead."); if (strand instanceof FiberStrand) return clone((Fiber) strand.getUnderlying(), target); if (strand instanceof Fiber) return new Fiber((Fiber) strand, target); else return ThreadStrand.get(cloneThread((Thread) strand.getUnderlying(), toRunnable(target))); }
/** * Returns a strand representing the given thread. */ public static Strand of(Thread thread) { return ThreadStrand.get(thread); }
@Override public void unpark(Object unblocker) { unpark(); }
public static Strand clone(Strand strand, final SuspendableCallable<?> target) { if (strand.isAlive()) throw new IllegalStateException("A strand can only be cloned after death. " + strand + " isn't dead."); if (strand instanceof FiberStrand) return clone((Fiber) strand.getUnderlying(), target); if (strand instanceof Fiber) return new Fiber((Fiber) strand, target); else return ThreadStrand.get(cloneThread((Thread) strand.getUnderlying(), toRunnable(target))); }