Beispiel #1
0
void PendQ::drain() {
  assert(currentRank() == RankBase); // Call from base rank.
  while (tl_q && !tl_q->empty()) {
    DeferredWorkItem* i = tl_q->front();
    tl_q->pop();
    (*i)();
    assert(currentRank() == RankBase); // Don't hold locks.
    delete i;
  }
}
Beispiel #2
0
/*
 * Returns number of destroyed references to file.
 */
size_t SrcDB::invalidateCode(const Eval::PhpFile* file) {
  ASSERT(currentRank() == RankBase);
  /*
   * Hold the write lease; otherwise some other thread may have started
   * translating this very file.
   */
  BlockingLeaseHolder writer(Translator::WriteLease());

  ASSERT(!RuntimeOption::RepoAuthoritative);
  unsigned i = 0;
  {
    TRACE(1, "SrcDB::invalidateCode: file %p\n", file);
    FileDepMap::iterator entry = m_deps.find(file);
    if (entry != m_deps.end()) {
      GrowableVector<SrcKey>* deferredSrcKeys = entry->second;
      for (/* already inited*/; i < deferredSrcKeys->size(); i++) {
        tx64->invalidateSrcKey((*deferredSrcKeys)[i]);
      }
      TRACE(1, "SrcDB::invalidateCode: file %p has %zd srcKeys\n", file,
            entry->second->size());
      m_deps.erase(entry);
      free(deferredSrcKeys);
    }
  }
  return i;
}
Beispiel #3
0
/*
 * Insert a rank that may be lower than the current rank in an
 * appropriate position in the stack. This should only be used after a
 * successful trylock of a lock with rank r.
 */
void insertRank(Rank r) {
  assert(r != RankUnranked);
  if (currentRank() <= r) {
    pushRank(r);
    return;
  }
  // Find the first real rank < r
  int i;
  for (i = tl_curRankDepth; i >= 0; i--) {
    if (tl_rankStack[i] < r && tl_rankStack[i] != RankUnranked) {
      break;
    }
  }
  memmove(&tl_rankStack[i+1], &tl_rankStack[i],
          sizeof(Rank) * (tl_curRankDepth - i));
  tl_rankStack[i] = r;
}
Beispiel #4
0
void checkRank(Rank r) {
  if (tl_curRankDepth >= 1) {
    Rank prev = currentRank();
    /*
     * >= implies the ranks are a total order. If you want to allow
     * partial orders, make the constituent locks unranked.
     */
    if (prev >= r && r != RankUnranked) {
      if (r == RankLeaf) {
        fprintf(stderr, "Rank violation in thr%lx! leaf lock from leaf rank; ",
                pthread_self());
      } else {
        fprintf(stderr, "Rank violation in thr%lx! lock of rank %d; ",
                pthread_self(), r);
      }
      fprintf(stderr, "held locks:\n");
      for (int i = tl_curRankDepth - 1; i >= 0; --i) {
        fprintf(stderr, "%10d\n", tl_rankStack[i]);
      }
      assert(false);
    }
  }
}