Requires a {@link LockMode#WRITE} lock.
3532
public Addon getAddon(final AddonView view, final AddonId id)
   {
      Assert.notNull(view, "AddonView must not be null.");
      Assert.notNull(id, "AddonId must not be null.");
      return lock.performLocked(LockMode.WRITE, new Callable<Addon>()
      {
         @Override
         public Addon call() throws Exception
         {
            Addon result = null;

            for (Addon addon : getAddons(view))
            {
               if (id.equals(addon.getId()))
               {
                  result = addon;
                  break;
               }
            }

            if (result == null)
            {
               result = stateManager.getAddonForView(view, id);
               if (result == null)
                  result = new AddonImpl(stateManager, id);

               Set<Addon> addons = _getAddonsForView(view);
               addons.add(result);
            }

            return result;
         }

      });
   }
1350356
def _write_lock(self):
        
        if self._lock:
            lgr.debug("Acquiring write lock")
            self._lock.acquire()
        try:
            yield
        finally:
            if self._lock:
                lgr.debug("Releasing write lock")
                self._lock.release()
536501
@Override
    public void write(final Writer writer) throws ConfigurationException, IOException {
        Preconditions.checkNotNull(writer);

        @SuppressWarnings("unchecked") final
        HashMap<String, Object> settings = (HashMap<String, Object>) fromNode(this.getModel().getInMemoryRepresentation());
        this.mapper.writerWithDefaultPrettyPrinter().writeValue(writer, settings);
    }
130105
@Override
    public synchronized Lock obtainReadLock() {
        File writeLock = getWriteLock();

        if (writeLock != null && writeLock.exists()) {
            return null;
        }

        return createLock(false);
    }
782560
public Optional<LockResource> tryGet(K key, LockMode mode) {
    ValNode valNode = getValNode(key);
    ReentrantReadWriteLock lock = valNode.mValue;
    Lock innerLock;
    switch (mode) {
      case READ:
        innerLock = lock.readLock();
        break;
      case WRITE:
        innerLock = lock.writeLock();
        break;
      default:
        throw new IllegalStateException("Unknown lock mode: " + mode);
    }
    if (!innerLock.tryLock()) {
      return Optional.empty();
    }
    return Optional.of(new RefCountLockResource(innerLock, false, valNode.mRefCount));
  }
929522
private static boolean tryWriteLockMillis(
            long address, long timeInMillis, boolean interruptible) throws InterruptedException {
        long lastTime = System.currentTimeMillis();
        registerWait(address);
        try {
            do {
                if (LOCK.tryWriteLockAndDeregisterWait(A, null, address + LOCK_OFFSET))
                    return true;
                checkInterrupted(interruptible);
                ThreadHints.onSpinWait();
                long now = System.currentTimeMillis();
                if (now != lastTime) {
                    lastTime = now;
                    timeInMillis--;
                }
            } while (timeInMillis >= 0);
            deregisterWait(address);
            return false;
        } catch (Throwable t) {
            throw tryDeregisterWaitAndRethrow(address, t);
        }
    }
796116
@Override
  public WriteLockedOffHeapHashMap<K, V> newInstance() {
    StorageEngine<? super K, ? super V> storageEngine = storageEngineFactory.newInstance();
    try {
      return new WriteLockedOffHeapHashMap<>(tableSource, storageEngine, tableSize);
    } catch (RuntimeException e) {
      storageEngine.destroy();
      throw e;
    }
  }
1236982
public int writeLocked (@Nonnull final IntSupplier aSupplier)
  {
    writeLock ().lock ();
    try
    {
      return aSupplier.getAsInt ();
    }
    finally
    {
      writeLock ().unlock ();
    }
  }
1353788
@CheckForNull
    public static LockingStrategy create( @Nullable final LockingMode lockingMode, @Nullable final Pattern uriPattern,
            @Nullable final StorageClient storage, @Nonnull final MemcachedSessionService manager,
            @Nonnull final MemcachedNodesManager memcachedNodesManager,
            @Nonnull final LRUCache<String, Boolean> missingSessionsCache, final boolean storeSecondaryBackup,
            @Nonnull final Statistics stats,
            @Nonnull final CurrentRequest currentRequest ) {
        if ( lockingMode == null || storage == null ) {
            return null;
        }
        switch ( lockingMode ) {
        case ALL:
            return new LockingStrategyAll( manager, memcachedNodesManager, storage, missingSessionsCache, storeSecondaryBackup, stats, currentRequest );
        case AUTO:
            return new LockingStrategyAuto( manager, memcachedNodesManager, storage, missingSessionsCache, storeSecondaryBackup, stats, currentRequest );
        case URI_PATTERN:
            return new LockingStrategyUriPattern( manager, memcachedNodesManager, uriPattern, storage, missingSessionsCache, storeSecondaryBackup,
                    stats, currentRequest );
        case NONE:
            return new LockingStrategyNone( manager, memcachedNodesManager, storage, missingSessionsCache, storeSecondaryBackup, stats, currentRequest );
        default:
            throw new IllegalArgumentException( "LockingMode not yet supported: " + lockingMode );
        }
    }
1142937
public int syncWriteTo(RingByteBuffer ring) throws IOException, InterruptedException
    {
        writeToLock.lock();
        try
        {
            getSync.waitUntil(()->hasRemaining());
            getAll(false);
            int rc = super.writeTo(ring);
            discard();
            return rc;
        }
        finally
        {
            writeToLock.unlock();
        }
    }
530964
public LockResource lockInode(InodeView inode, LockMode mode) {
    return mInodeLocks.get(inode.getId(), mode);
  }
735722
private <R> R doWithWriteLock(Action<K, V, R> action) {
        writeLock.lock();
        try {
            return action.doWith(commonCache);
        } finally {
            writeLock.unlock();
        }
    }
1052964
public void write(int c) {
        try {
            synchronized (lock) {
                ensureOpen();
                out.write(c);
            }
        }
        catch (InterruptedIOException x) {
            Thread.currentThread().interrupt();
        }
        catch (IOException x) {
            trouble = true;
        }
    }
997889
@Override
    public void lock(Object entity, LockModeType lockMode)
    {
        ivEm.lock(entity, lockMode);
    }
1037154
public void releaseLock(Object key) {
      ReentrantReadWriteLock lock = getLock(key);
      if (lock.isWriteLockedByCurrentThread()) {
         lock.writeLock().unlock();
         if (trace) log.tracef("WL released for '%s'", key);
      } else {
         lock.readLock().unlock();
         if (trace) log.tracef("RL released for '%s'", key);
      }
   }
944121
def release_write_lock
      while(true)
        c = @counter.value
        if @counter.compare_and_swap(c,c-RUNNING_WRITER)
          @reader_mutex.synchronize { @reader_q.broadcast }
          if waiting_writers(c) > 0
            @writer_mutex.synchronize { @writer_q.signal }
          end
          break
        end
      end
      true
    end
328158
private File getWriteLock() {
        File[] lckFiles = this.lockPath.listFiles(lockFilter);
        for (final File lckFile : lckFiles) {
            if (lockFilter.isWriterLockFile(lckFile)) {
                return lckFile;
            }
        }

        return null;
    }