_unlock(true); return retval;
public void lock() { try { acquire(false); } catch(InterruptedException e) { // should never happen Thread.currentThread().interrupt(); // just a second line of defense } }
public boolean tryLock(long time, TimeUnit unit) throws InterruptedException { return acquireTryLock(TimeUnit.MILLISECONDS.convert(time, unit), true); }
if(info.isLockInterruptibly()) { try { lock.lockInterruptibly(); lock.lock(); return lock.tryLock(info.getTimeout(), info.getTimeUnit()); return lock.tryLock(); lock=getLock(info.getName(), false); if(lock != null) lock.unlock(); return null; throw new IllegalMonitorStateException(); Condition condition = lock.newCondition(); if (info.isUseTimeout()) { try {
_unlock(true); return retval;
protected synchronized void acquire(boolean throwInterrupt) throws InterruptedException { if(acquired) return; if(throwInterrupt && Thread.interrupted()) throw new InterruptedException(); owner=getOwner(); sendGrantLockRequest(name, lock_id, owner, 0, false); boolean interrupted=false; while(!acquired) { try { this.wait(); } catch(InterruptedException e) { if(throwInterrupt && !acquired) { _unlock(true); throw e; } // If we don't throw exceptions then we just set the interrupt flag and let it loop around interrupted=true; } } if(interrupted) Thread.currentThread().interrupt(); }
@Override public void await() throws InterruptedException { InterruptedException ex = null; try { await(true); } catch (InterruptedException e) { ex = e; throw ex; } finally { lock.lock(); // If we are throwing an InterruptedException // then clear the interrupt state as well. if (ex != null) { Thread.interrupted(); } } }
@Override public long awaitNanos(long nanosTimeout) throws InterruptedException { InterruptedException ex = null; try { return await(nanosTimeout); } catch (InterruptedException e) { ex = e; throw ex; } finally { lock.lock(); // contract mandates we need to re-acquire the lock (see overridden method) // If we are throwing an InterruptedException then clear the interrupt state as well if (ex != null) Thread.interrupted(); } }
protected synchronized void _unlock(boolean force) { if(!acquired && !denied && !force) return; this.timeout=0; this.is_trylock=false; if(!denied) { if(!force) client_lock_table.addToPendingReleaseRequests(this); sendReleaseLockRequest(name, lock_id, owner); // lock will be released on RELEASE_LOCK_OK response if(force && client_lock_table.removeClientLock(name,owner)) notifyLockDeleted(name); } else _unlockOK(); }
public boolean tryLock(long time, TimeUnit unit) throws InterruptedException { return acquireTryLock(TimeUnit.MILLISECONDS.convert(time, unit), true); }
protected ClientLock createLock(String lock_name, Owner owner) { return new ClientLock(lock_name, owner); }
public void lockInterruptibly() throws InterruptedException { acquire(true); }
public synchronized void unlock() { _unlock(false); }
public boolean tryLock() { try { return acquireTryLock(0, false); } catch(InterruptedException e) { Thread.currentThread().interrupt(); return false; } }
protected void handleLockReleasedResponse(String lock_name, int lock_id, Owner owner) { ClientLock lock=client_lock_table.getLock(lock_name,owner,false); if(lock != null) lock.handleLockReleasedResponse(lock_id); }
protected void handleLockGrantedResponse(String lock_name, int lock_id, Owner owner) { ClientLock lock=client_lock_table.getLock(lock_name,owner,false); if(lock != null) lock.handleLockGrantedResponse(lock_id); }
public void lock() { try { acquire(false); } catch(InterruptedException e) { // should never happen Thread.currentThread().interrupt(); // just a second line of defense } }
@Override public void awaitUninterruptibly() { try { await(false); } catch(InterruptedException e) { // This should never happen } finally { lock.lock(); } }
public String printLocks() { return table.values().stream().map(Map::values).flatMap(Collection::stream) .filter(cl -> cl.isHeld() && Objects.nonNull(cl.name)) .map(cl -> cl.name).collect(Collectors.joining(", ")); }
protected void unlockForce(String lock_name) { Map<Owner,ClientLock> owners=table.get(lock_name); if(owners != null) { for(ClientLock cl : owners.values()) cl._unlock(true); } pending_release_reqs.removeIf(cl -> Objects.equals(cl.name, lock_name)); }