Package co.paralleluniverse.strands

Examples of co.paralleluniverse.strands.Strand


     * @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

     * {@linkplain Strand#getName name} of the owning strand.
     *
     * @return a string identifying this lock, as well as its lock state
     */
    public String toString() {
        Strand o = sync.getOwner();
        return super.toString() + ((o == null) ?
                                   "[Unlocked]" :
                                   "[Locked by strand " + o.getName() + "]");
    }
View Full Code Here

         * Performs non-fair tryLock.  tryAcquire is
         * implemented in subclasses, but both need nonfair
         * try for trylock method.
         */
        final boolean nonfairTryAcquire(int acquires) {
            final Strand current = Strand.currentStrand();
            int c = getState();
            if (c == 0) {
                if (compareAndSetState(0, acquires)) {
                    setExclusiveOwnerStrand(current);
                    return true;
View Full Code Here

        /**
         * Fair version of tryAcquire.  Don't grant access unless
         * recursive call or no waiters or is first.
         */
        protected final boolean tryAcquire(int acquires) {
            final Strand current = Strand.currentStrand();
            int c = getState();
            if (c == 0) {
                if (!hasQueuedPredecessors() &&
                    compareAndSetState(0, acquires)) {
                    setExclusiveOwnerStrand(current);
View Full Code Here

     * @param nanos timeout in nanosecs, used only if timed is true
     * @return matched item, or e if unmatched on interrupt or timeout
     */
    private Message awaitMatch(Node s, Node pred, Message e, boolean timed, long nanos) throws SuspendExecution {
        long lastTime = timed ? System.nanoTime() : 0L;
        Strand w = Strand.currentStrand();
        int spins = (w.isFiber() ? 0 : -1); // no spins in fiber; otherwise, initialized after first item and cancel checks
        ThreadLocalRandom randomYields = null; // bound if needed

        if (spins == 0)
            requestUnpark(s, w);

        for (;;) {
            Object item = s.item;

            if (item == CHANNEL_CLOSED)
                setReceiveClosed();

            if (item != e) {                  // matched
                // assert item != s;
                s.forgetContents();           // avoid garbage
                return this.<Message>cast(item);
            }
            if ((w.isInterrupted() || (timed && nanos <= 0))
                    && s.casItem(e, s)) {     // cancel
                unsplice(pred, s);
                return e;
            }

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.