Package co.paralleluniverse.strands

Examples of co.paralleluniverse.strands.Strand


         * some other strand(s) concurrently performed setHead in
         * between some of our reads. We try this twice before
         * resorting to traversal.
         */
        Node h, s;
        Strand st;
        if (((h = head) != null && (s = h.next) != null &&
             s.prev == head && (st = s.strand) != null) ||
            ((h = head) != null && (s = h.next) != null &&
             s.prev == head && (st = s.strand) != null))
            return st;

        /*
         * Head's next field might not have been set yet, or may have
         * been unset after setHead. So we must check to see if tail
         * is actually first node. If not, we continue on, safely
         * traversing from tail back to head to find first,
         * guaranteeing termination.
         */

        Node t = tail;
        Strand firstStrand = null;
        while (t != null && t != head) {
            Strand tt = t.strand;
            if (tt != null)
                firstStrand = tt;
            t = t.prev;
        }
        return firstStrand;
View Full Code Here


     * @return the collection of strands
     */
    public final Collection<Strand> getQueuedStrands() {
        ArrayList<Strand> list = new ArrayList<Strand>();
        for (Node p = tail; p != null; p = p.prev) {
            Strand t = p.strand;
            if (t != null)
                list.add(t);
        }
        return list;
    }
View Full Code Here

     */
    public final Collection<Strand> getExclusiveQueuedStrands() {
        ArrayList<Strand> list = new ArrayList<Strand>();
        for (Node p = tail; p != null; p = p.prev) {
            if (!p.isShared()) {
                Strand t = p.strand;
                if (t != null)
                    list.add(t);
            }
        }
        return list;
View Full Code Here

     */
    public final Collection<Strand> getSharedQueuedStrands() {
        ArrayList<Strand> list = new ArrayList<Strand>();
        for (Node p = tail; p != null; p = p.prev) {
            if (p.isShared()) {
                Strand t = p.strand;
                if (t != null)
                    list.add(t);
            }
        }
        return list;
View Full Code Here

            if (!isHeldExclusively())
                throw new IllegalMonitorStateException();
            ArrayList<Strand> list = new ArrayList<Strand>();
            for (Node w = firstWaiter; w != null; w = w.nextWaiter) {
                if (w.waitStatus == Node.CONDITION) {
                    Strand t = w.strand;
                    if (t != null)
                        list.add(t);
                }
            }
            return list;
View Full Code Here

        } else {
            try {
                final ShutdownMessage message = new ShutdownMessage(LocalActor.self());
                sendOrInterrupt(message);
            } catch (QueueCapacityExceededException e) {
                final Strand strand = getStrand();
                if (strand != null)
                    strand.interrupt();
            }
        }
    }
View Full Code Here

        return start(child, actor);
    }

    private LocalActor start(ChildEntry child, LocalActor actor) {
        final Strand strand;
        if (actor.getStrand() != null)
            strand = actor.getStrand();
        else
            strand = createStrandForActor(child.actor != null ? child.actor.getStrand() : null, actor);

        child.actor = actor;
        child.watch = watch(actor);

        try {
            strand.start();
        } catch (IllegalThreadStateException e) {
            LOG.info("Child {} has already been started.", actor);
        }
        return actor;
    }
View Full Code Here

            child.watch = null;
        }
    }

    private Strand createStrandForActor(Strand oldStrand, LocalActor actor) {
        final Strand strand;
        if (oldStrand != null)
            strand = Strand.clone(oldStrand, actor);
        else
            strand = new Fiber(actor);
        actor.setStrand(strand);
View Full Code Here

             * 3. Otherwise, this strand is eligible for lock if
             *    it is either a reentrant acquire or
             *    queue policy allows it. If so, update state
             *    and set owner.
             */
            Strand current = Strand.currentStrand();
            int c = getState();
            int w = exclusiveCount(c);
            if (c != 0) {
                // (Note: if c != 0 and w == 0 then shared count != 0)
                if (w == 0 || current != getExclusiveOwnerStrand())
View Full Code Here

            setExclusiveOwnerStrand(current);
            return true;
        }

        protected final boolean tryReleaseShared(int unused) {
            Strand current = Strand.currentStrand();
            if (firstReader == current) {
                // assert firstReaderHoldCount > 0;
                if (firstReaderHoldCount == 1)
                    firstReader = null;
                else
                    firstReaderHoldCount--;
            } else {
                HoldCounter rh = cachedHoldCounter;
                if (rh == null || rh.tid != current.getId())
                    rh = readHolds.get();
                int count = rh.count;
                if (count <= 1) {
                    readHolds.remove();
                    if (count <= 0)
View Full Code Here

TOP

Related Classes of co.paralleluniverse.strands.Strand

Copyright © 2018 www.massapicom. All rights reserved.
All source code are property of their respective owners. Java is a trademark of Sun Microsystems, Inc and owned by ORACLE Inc. Contact coftware#gmail.com.