Examples of Strand


Examples of co.paralleluniverse.strands.Strand

        WNode node = null, group = null, p;
        for (int spins = -1;;) {
            for (;;) {
                long s, m, ns;
                WNode h, q;
                Strand w; // anti-barging guard
                if (group == null && (h = whead) != null
                        && (q = h.next) != null && q.mode != RMODE)
                    break;
                if ((m = (s = state) & ABITS) < RFULL
                        ? U.compareAndSwapLong(this, STATE, s, ns = s + RUNIT)
                        : (m < WBIT && (ns = tryIncReaderOverflow(s)) != 0L)) {
                    if (group != null) {  // help release others
                        for (WNode r = group;;) {
                            if ((w = r.strand) != null) {
                                r.strand = null;
                                w.unpark();
                            }
                            if ((r = group.cowait) == null)
                                break;
                            U.compareAndSwapObject(group, WCOWAIT, r, r.cowait);
                        }
                    }
                    return ns;
                }
                if (m >= WBIT)
                    break;
            }
            if (spins > 0) {
                if (ThreadLocalRandom.current().nextInt() >= 0)
                    --spins;
            } else if ((p = wtail) == null) {
                WNode h = new WNode(WMODE, null);
                if (U.compareAndSwapObject(this, WHEAD, null, h))
                    wtail = h;
            } else if (spins < 0)
                spins = (p == whead) ? SPINS : 0;
            else if (node == null)
                node = new WNode(WMODE, p);
            else if (node.prev != p)
                node.prev = p;
            else if (p.mode == RMODE && p != whead) {
                WNode pp = p.prev;  // become co-waiter with group p
                if (pp != null && p == wtail
                        && U.compareAndSwapObject(p, WCOWAIT,
                        node.cowait = p.cowait, node)) {
                    node.strand = Strand.currentStrand();
                    for (long time;;) {
                        if (interruptible && Strand.interrupted())
                            return cancelWaiter(node, p, true);
                        if (deadline == 0L)
                            time = 0L;
                        else if ((time = deadline - System.nanoTime()) <= 0L)
                            return cancelWaiter(node, p, false);
                        if (node.strand == null)
                            break;
                        if (p.prev != pp || p.status == CANCELLED
                                || p == whead || p.prev != pp) {
                            node.strand = null;
                            break;
                        }
                        if (node.strand == null) // must recheck
                            break;
                        park(time);
                    }
                    group = p;
                }
                node = null; // throw away
            } else if (U.compareAndSwapObject(this, WTAIL, p, node)) {
                p.next = node;
                break;
            }
        }

        for (int spins = SPINS;;) {
            WNode np, pp, r;
            int ps;
            long m, s, ns;
            Strand w;
            while ((np = node.prev) != p && np != null)
                (p = np).next = node;
            if (whead == p) {
                for (int k = spins;;) {
                    if ((m = (s = state) & ABITS) != WBIT) {
                        if (m < RFULL
                                ? U.compareAndSwapLong(this, STATE, s, ns = s + RUNIT)
                                : (ns = tryIncReaderOverflow(s)) != 0L) {
                            whead = node;
                            node.prev = null;
                            while ((r = node.cowait) != null) {
                                if (U.compareAndSwapObject(node, WCOWAIT,
                                        r, r.cowait)
                                        && (w = r.strand) != null) {
                                    r.strand = null;
                                    w.unpark(); // release co-waiter
                                }
                            }
                            return ns;
                        }
                    } else if (ThreadLocalRandom.current().nextInt() >= 0
View Full Code Here

Examples of co.paralleluniverse.strands.Strand

     * @param interrupted if already interrupted
     * @return INTERRUPTED if interrupted or Strand.interrupted, else zero
     */
    private long cancelWaiter(WNode node, WNode group, boolean interrupted) {
        if (node != null && group != null) {
            Strand w;
            node.status = CANCELLED;
            node.strand = null;
            // unsplice cancelled nodes from group
            for (WNode p = group, q; (q = p.cowait) != null;) {
                if (q.status == CANCELLED)
                    U.compareAndSwapObject(p, WNEXT, q, q.next);
                else
                    p = q;
            }
            if (group == node) {
                WNode r; // detach and wake up uncancelled co-waiters
                while ((r = node.cowait) != null) {
                    if (U.compareAndSwapObject(node, WCOWAIT, r, r.cowait)
                            && (w = r.strand) != null) {
                        r.strand = null;
                        w.unpark();
                    }
                }
                for (WNode pred = node.prev; pred != null;) { // unsplice
                    WNode succ, pp;        // find valid successor
                    while ((succ = node.next) == null
                            || succ.status == CANCELLED) {
                        WNode q = null;    // find successor the slow way
                        for (WNode t = wtail; t != null && t != node; t = t.prev)
                            if (t.status != CANCELLED)
                                q = t;     // don't link if succ cancelled
                        if (succ == q || // ensure accurate successor
                                U.compareAndSwapObject(node, WNEXT,
                                succ, succ = q)) {
                            if (succ == null && node == wtail)
                                U.compareAndSwapObject(this, WTAIL, node, pred);
                            break;
                        }
                    }
                    if (pred.next == node) // unsplice pred link
                        U.compareAndSwapObject(pred, WNEXT, node, succ);
                    if (succ != null && (w = succ.strand) != null) {
                        succ.strand = null;
                        w.unpark();       // wake up succ to observe new pred
                    }
                    if (pred.status != CANCELLED || (pp = pred.prev) == null)
                        break;
                    node.prev = pp;        // repeat if new pred wrong/cancelled
                    U.compareAndSwapObject(pp, WNEXT, pred, succ);
View Full Code Here

Examples of co.paralleluniverse.strands.Strand

    /**
     * Removes and signals threads from queue for phase.
     */
    private void releaseWaiters(int phase) {
        QNode q;   // first element of queue
        Strand t;  // its strand
        AtomicReference<QNode> head = (phase & 1) == 0 ? evenQ : oddQ;
        // int total = 0;  // contention profiling
        // int failed = 0; // contention profiling
        while ((q = head.get()) != null
                && q.phase != (int) (root.state >>> PHASE_SHIFT)) {
View Full Code Here

Examples of co.paralleluniverse.strands.Strand

    private int abortWait(int phase) {
        AtomicReference<QNode> head = (phase & 1) == 0 ? evenQ : oddQ;
        // int total = 0;  // contention profiling
        //int failed = 0; // contention profiling
        for (;;) {
            Strand t;
            QNode q = head.get();
            int p = (int) (root.state >>> PHASE_SHIFT);
            if (q == null || ((t = q.strand) != null && q.phase == p)) {
                // if (total > 0)
                //    System.out.println("PHASER: " + Fiber.currentFiber() + " abortWait: " + failed + '/' + total + " " + ((double)failed / total));
View Full Code Here

Examples of co.paralleluniverse.strands.Strand

        return flightRecorder;
    }

    @SuppressWarnings("CallToThreadDumpStack")
    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

Examples of org.broad.igv.feature.Strand

            for (AlignmentBlock b : blocks) {
                if (b.getEnd() < start) continue;
                if (b.getStart() > end) break;

                //Strand strand = alignment.getFirstOfPairStrand();
                Strand strand = alignment.getReadStrand();

                // Don't count softclips
                if (!b.isSoftClipped() && strand != Strand.NONE) {
                    final boolean isNegativeStrand = strand == Strand.NEGATIVE;
View Full Code Here

Examples of org.broad.igv.feature.Strand

                return al.getReadGroup();
            case TAG:
                Object tagValue = al.getAttribute(tag);
                return tagValue == null ? null : tagValue.toString();
            case FIRST_OF_PAIR_STRAND:
                Strand strand = al.getFirstOfPairStrand();
                String strandString = strand == Strand.NONE ? null : strand.toString();
                System.out.println(strandString);
                return strandString;
            case PAIR_ORIENTATION:
                PEStats peStats = AlignmentRenderer.getPEStats(al, renderOptions);
                AlignmentTrack.OrientationType type = AlignmentRenderer.getOrientationType(al, peStats);
View Full Code Here

Examples of org.broad.igv.feature.Strand

    @Test
    public void testBasicSearchNegStrand_end() throws Exception{
        int posStart = 19389;
        //Motif is at the end of this sequence on the negative strand
        String motif = "CTGATC";
        Strand strand = Strand.NEGATIVE;

        Iterator<Feature> matchIter = MotifFinderSource.searchSingleStrand(motif, strand, null, posStart, shortSeq.getBytes());
        assertTrue("No matches found for motif " + motif, matchIter.hasNext());
        Feature feat = matchIter.next();
View Full Code Here

Examples of org.broad.igv.feature.Strand

    public void testBasicSearchNegStrand_few() throws Exception{
        int posStart = 19389;
        //Should have several hits
        String motif = "TG";
        String revSeq = "CA";
        Strand strand = Strand.NEGATIVE;

        Iterator<Feature> matchIter = MotifFinderSource.searchSingleStrand(motif, strand, null, posStart, shortSeq.getBytes());
        assertTrue("No matches found for motif " + motif, matchIter.hasNext());

        while(matchIter.hasNext()){
View Full Code Here

Examples of org.broad.igv.feature.Strand

    @Test
    public void testSearchSingleStrandPos() throws Exception{
        int posStart = 19389;
        String motif = "TCTG";
        Strand strand = Strand.POSITIVE;

        Iterator<Feature> matchIter = MotifFinderSource.searchSingleStrand(motif, strand, null, posStart, shortSeq.getBytes());
        assertTrue("No matches found for motif " + motif, matchIter.hasNext());
        Feature feat = matchIter.next();
View Full Code Here
TOP
Copyright © 2018 www.massapi.com. 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.