Search in sources :

Example 66 with ReentrantLock

use of java.util.concurrent.locks.ReentrantLock in project geode by apache.

the class ForceableLinkedBlockingQueue method signalNotEmpty.

/**
   * Signals a waiting take. Called only from put/offer (which do not otherwise ordinarily lock
   * takeLock.)
   */
private void signalNotEmpty() {
    final ReentrantLock takeLock = this.takeLock;
    takeLock.lock();
    try {
        notEmpty.signal();
    } finally {
        takeLock.unlock();
    }
}
Also used : ReentrantLock(java.util.concurrent.locks.ReentrantLock)

Example 67 with ReentrantLock

use of java.util.concurrent.locks.ReentrantLock in project geode by apache.

the class ForceableLinkedBlockingQueue method signalNotFull.

/**
   * Signals a waiting put. Called only from take/poll.
   */
private void signalNotFull() {
    final ReentrantLock putLock = this.putLock;
    putLock.lock();
    try {
        notFull.signal();
    } finally {
        putLock.unlock();
    }
}
Also used : ReentrantLock(java.util.concurrent.locks.ReentrantLock)

Example 68 with ReentrantLock

use of java.util.concurrent.locks.ReentrantLock in project geode by apache.

the class ForceableLinkedBlockingQueue method poll.

public E poll() {
    final AtomicInteger count = this.count;
    if (count.get() == 0)
        return null;
    E x = null;
    int c = -1;
    final ReentrantLock takeLock = this.takeLock;
    takeLock.lock();
    try {
        if (count.get() > 0) {
            x = dequeue();
            c = count.getAndDecrement();
            if (c > 1)
                notEmpty.signal();
        }
    } finally {
        takeLock.unlock();
    }
    if (c == capacity)
        signalNotFull();
    return x;
}
Also used : ReentrantLock(java.util.concurrent.locks.ReentrantLock) AtomicInteger(java.util.concurrent.atomic.AtomicInteger)

Example 69 with ReentrantLock

use of java.util.concurrent.locks.ReentrantLock in project geode by apache.

the class ForceableLinkedBlockingQueue method take.

public E take() throws InterruptedException {
    E x;
    int c = -1;
    final AtomicInteger count = this.count;
    final ReentrantLock takeLock = this.takeLock;
    takeLock.lockInterruptibly();
    try {
        while (count.get() == 0) {
            notEmpty.await();
        }
        x = dequeue();
        c = count.getAndDecrement();
        if (c > 1)
            notEmpty.signal();
    } finally {
        takeLock.unlock();
    }
    if (c == capacity)
        signalNotFull();
    return x;
}
Also used : ReentrantLock(java.util.concurrent.locks.ReentrantLock) AtomicInteger(java.util.concurrent.atomic.AtomicInteger)

Example 70 with ReentrantLock

use of java.util.concurrent.locks.ReentrantLock in project sling by apache.

the class JspRuntimeContext method getTagFileLoadingLock.

/**
     * Returns and optionally creates a lock to load a tag file.
     */
private Lock getTagFileLoadingLock(final String tagFilePath) {
    Lock lock = tagFileLoadingLocks.get(tagFilePath);
    if (lock == null) {
        lock = new ReentrantLock();
        final Lock existingLock = tagFileLoadingLocks.putIfAbsent(tagFilePath, lock);
        if (existingLock != null) {
            lock = existingLock;
        }
    }
    return lock;
}
Also used : ReentrantLock(java.util.concurrent.locks.ReentrantLock) ReentrantLock(java.util.concurrent.locks.ReentrantLock) Lock(java.util.concurrent.locks.Lock)

Aggregations

ReentrantLock (java.util.concurrent.locks.ReentrantLock)1524 Lock (java.util.concurrent.locks.Lock)125 Test (org.junit.Test)78 AtomicInteger (java.util.concurrent.atomic.AtomicInteger)74 Condition (java.util.concurrent.locks.Condition)57 ArrayList (java.util.ArrayList)45 IOException (java.io.IOException)42 AtomicBoolean (java.util.concurrent.atomic.AtomicBoolean)27 File (java.io.File)22 TimeoutException (java.util.concurrent.TimeoutException)19 Before (org.junit.Before)18 AtomicReference (java.util.concurrent.atomic.AtomicReference)17 HashMap (java.util.HashMap)16 CountDownLatch (java.util.concurrent.CountDownLatch)16 ExecutionException (java.util.concurrent.ExecutionException)15 List (java.util.List)14 AtomicLong (java.util.concurrent.atomic.AtomicLong)14 Map (java.util.Map)11 ConcurrentHashMap (java.util.concurrent.ConcurrentHashMap)11 Pair (android.util.Pair)10