Examples of StampedLock


Examples of jersey.repackaged.jsr166e.StampedLock

    /** See {@link Vector#lastIndexOf(Object, int)} */
    public int lastIndexOf(Object o, int index) {
        boolean oobe = false;
        int idx = -1;
        final StampedLock lock = this.lock;
        long stamp = lock.readLock();
        try {
            if (index < count)
                idx = findLastIndex(array, o, index, 0);
            else
                oobe = true;
        } finally {
            lock.unlockRead(stamp);
        }
        if (oobe)
            throw new ArrayIndexOutOfBoundsException(index);
        return idx;
    }
View Full Code Here

Examples of jersey.repackaged.jsr166e.StampedLock

    /** See {@link Vector#setSize} */
    public void setSize(int newSize) {
        if (newSize < 0)
            throw new ArrayIndexOutOfBoundsException(newSize);
        final StampedLock lock = this.lock;
        long stamp = lock.writeLock();
        try {
            Object[] items;
            int n = count;
            if (newSize > n)
                grow(newSize);
            else if ((items = array) != null) {
                for (int i = newSize ; i < n ; i++)
                    items[i] = null;
            }
            count = newSize;
        } finally {
            lock.unlockWrite(stamp);
        }
    }
View Full Code Here

Examples of jersey.repackaged.jsr166e.StampedLock

        }
    }

    /** See {@link Vector#copyInto} */
    public void copyInto(Object[] anArray) {
        final StampedLock lock = this.lock;
        long stamp = lock.writeLock();
        try {
            Object[] items;
            if ((items = array) != null)
                System.arraycopy(items, 0, anArray, 0, count);
        } finally {
            lock.unlockWrite(stamp);
        }
    }
View Full Code Here

Examples of jersey.repackaged.jsr166e.StampedLock

        }
    }

    /** See {@link Vector#trimToSize} */
    public void trimToSize() {
        final StampedLock lock = this.lock;
        long stamp = lock.writeLock();
        try {
            Object[] items = array;
            int n = count;
            if (items != null && n < items.length)
                array = Arrays.copyOf(items, n);
        } finally {
            lock.unlockWrite(stamp);
        }
    }
View Full Code Here

Examples of jersey.repackaged.jsr166e.StampedLock

    }

    /** See {@link Vector#ensureCapacity} */
    public void ensureCapacity(int minCapacity) {
        if (minCapacity > 0) {
            final StampedLock lock = this.lock;
            long stamp = lock.writeLock();
            try {
                Object[] items = array;
                int cap = (items == null) ? 0 : items.length;
                if (minCapacity - cap > 0)
                    grow(minCapacity);
            } finally {
                lock.unlockWrite(stamp);
            }
        }
    }
View Full Code Here

Examples of jersey.repackaged.jsr166e.StampedLock

    // other methods

    public ReadMostlyVector<E> clone() {
        Object[] a = null;
        int n;
        final StampedLock lock = this.lock;
        long stamp = lock.readLock();
        try {
            Object[] items = array;
            if (items == null)
                n = 0;
            else {
                int len = items.length;
                if ((n = count) > len)
                    n = len;
                a = Arrays.copyOf(items, n);
            }
        } finally {
            lock.unlockRead(stamp);
        }
        return new ReadMostlyVector<E>(a, n, capacityIncrement);
    }
View Full Code Here

Examples of jersey.repackaged.jsr166e.StampedLock

        return new ReadMostlyVector<E>(a, n, capacityIncrement);
    }

    private void writeObject(java.io.ObjectOutputStream s)
        throws java.io.IOException {
        final StampedLock lock = this.lock;
        long stamp = lock.readLock();
        try {
            s.defaultWriteObject();
        } finally {
            lock.unlockRead(stamp);
        }
    }
View Full Code Here

Examples of jersey.repackaged.jsr166e.StampedLock

        int cursor;
        int fence;
        int lastRet;

        Itr(ReadMostlyVector<E> list, int index) {
            final StampedLock lock = list.lock;
            long stamp = lock.readLock();
            try {
                this.list = list;
                this.lock = lock;
                this.items = list.array;
                this.fence = list.count;
                this.cursor = index;
                this.lastRet = -1;
            } finally {
                this.seq = lock.tryConvertToOptimisticRead(stamp);
            }
            if (index < 0 || index > fence)
                throw new ArrayIndexOutOfBoundsException(index);
        }
View Full Code Here

Examples of jersey.repackaged.jsr166e.StampedLock

            if (index < 0 || index >= size)
                throw new ArrayIndexOutOfBoundsException(index);
        }

        public boolean add(E element) {
            final StampedLock lock = list.lock;
            long stamp = lock.writeLock();
            try {
                int c = size;
                list.rawAddAt(c + offset, element);
                size = c + 1;
            } finally {
                lock.unlockWrite(stamp);
            }
            return true;
        }
View Full Code Here

Examples of jersey.repackaged.jsr166e.StampedLock

            }
            return true;
        }

        public void add(int index, E element) {
            final StampedLock lock = list.lock;
            long stamp = lock.writeLock();
            try {
                if (index < 0 || index > size)
                    throw new ArrayIndexOutOfBoundsException(index);
                list.rawAddAt(index + offset, element);
                ++size;
            } finally {
                lock.unlockWrite(stamp);
            }
        }
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.