Esempio n. 1
0
    public void lock(final long recid) {
      if (CC.LOG_LOCKS)
        Utils.LOG.finest("TRYLOCK R:" + recid + " T:" + Thread.currentThread().getId());

      // feel free to rewrite, if you know better (more efficient) way
      if (CC.ASSERT && locks.get(recid) == Thread.currentThread()) {
        // check node is not already locked by this thread
        throw new InternalError("node already locked by current thread: " + recid);
      }

      while (locks.putIfAbsent(recid, Thread.currentThread()) != null) {
        Thread.yield();
      }
      if (CC.LOG_LOCKS)
        Utils.LOG.finest("LOCK R:" + recid + " T:" + Thread.currentThread().getId());
    }
Esempio n. 2
0
    public void unlock(final long recid) {
      if (CC.LOG_LOCKS)
        Utils.LOG.finest("UNLOCK R:" + recid + " T:" + Thread.currentThread().getId());

      final Thread t = locks.remove(recid);
      if (t != Thread.currentThread()) throw new InternalError("unlocked wrong thread");
    }