release method

void release()

Release a lock.

Release a lock that has been acquired.

Implementation

void release() {
  if (_state == -1) {
    // Write lock released
    _state = 0;
  } else if (0 < _state) {
    // Read lock released
    _state--;
  } else if (_state == 0) {
    throw new StateError("no lock to release");
  } else {
    assert(false);
  }

  // Let all jobs that can now acquire a lock do so.

  while (_waiting.isNotEmpty) {
    var nextJob = _waiting.first;
    if (_jobAcquired(nextJob)) {
      _waiting.removeFirst();
    } else {
      break; // no more can be acquired
    }
  }
}