| | |
| | | // and either return it or return null. |
| | | readLock.unlock(); |
| | | readLock = existingLock.readLock(); |
| | | if (readLock.tryLock()) |
| | | |
| | | try |
| | | { |
| | | if (readLock.tryLock(0, TimeUnit.SECONDS)) |
| | | { |
| | | return readLock; |
| | | } |
| | |
| | | return null; |
| | | } |
| | | } |
| | | catch(InterruptedException ie) |
| | | { |
| | | // This should never happen. Just return null |
| | | return null; |
| | | } |
| | | } |
| | | else |
| | | { |
| | | // If this happens, then it means that while we were waiting |
| | |
| | | // and either return it or return null. |
| | | writeLock.unlock(); |
| | | writeLock = existingLock.writeLock(); |
| | | if (writeLock.tryLock()) |
| | | try |
| | | { |
| | | if (writeLock.tryLock(0, TimeUnit.SECONDS)) |
| | | { |
| | | return writeLock; |
| | | } |
| | |
| | | return null; |
| | | } |
| | | } |
| | | catch(InterruptedException ie) |
| | | { |
| | | // This should never happen. Just return null |
| | | return null; |
| | | } |
| | | } |
| | | else |
| | | { |
| | | // If this happens, then it means that while we were waiting |