Package co.paralleluniverse.strands

Examples of co.paralleluniverse.strands.Strand


    public static FlightRecorder getGlobalFlightRecorder() {
        return flightRecorder;
    }

    public static void exit(int code) {
        final Strand currentStrand = Strand.currentStrand();
        if (flightRecorder != null) {
            flightRecorder.record(1, "DEBUG EXIT REQUEST ON STRAND " + currentStrand + ": " + Arrays.toString(currentStrand.getStackTrace()));
            flightRecorder.stop();
        }

        if (requestShutdown.compareAndSet(false, true)) {
            System.err.println("DEBUG EXIT REQUEST ON STRAND " + currentStrand
                    + (currentStrand.isFiber() ? " (THREAD " + Thread.currentThread() + ")" : "")
                    + ": SHUTTING DOWN THE JVM.");
            Thread.dumpStack();
            if (!isUnitTest()) // Calling System.exit() in gradle unit tests breaks gradle
                System.exit(code);
            else
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

         * 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

     * methods themselves provide extra safeguards to ensure liveness.
     */
    private void release(WNode h) {
        if (h != null) {
            WNode q;
            Strand w;
            U.compareAndSwapInt(h, WSTATUS, WAITING, 0);
            if ((q = h.next) == null || q.status == CANCELLED) {
                for (WNode t = wtail; t != null && t != h; t = t.prev)
                    if (t.status <= 0)
                        q = t;
            }
            if (q != null) {
                for (WNode r = q;;) {  // release co-waiters too
                    if ((w = r.strand) != null) {
                        r.strand = null;
                        w.unpark();
                    }
                    if ((r = q.cowait) == null)
                        break;
                    U.compareAndSwapObject(q, WCOWAIT, r, r.cowait);
                }
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.