@Override
    public boolean tryLock(long time, TimeUnit unit) throws InterruptedException {
      boolean result = false;
      long startTime = System.nanoTime();

      ReentrantLock compileLock = SessionState.get().getCompileLock();
      try {
        result = compileLock.tryLock(time, unit)
            && globalCompileQuotas.tryAcquire(
                getRemainingTime(startTime, unit.toNanos(time)), TimeUnit.NANOSECONDS);
      } finally {
        if (!result && compileLock.isHeldByCurrentThread()) {
          compileLock.unlock();
        }
      }
      return result;
    }
Combination of global semaphore and session reentrant lock.
ql/src/java/org/apache/hadoop/hive/ql/lock/CompileLockFactory.java