Esempio n. 1
0
  @Override
  public long allocatePages(long pageCount) throws IOException {
    if (pageCount <= 0) {
      return 0;
    }

    Stats stats = new Stats();
    mPageManager.addTo(stats);
    pageCount -= stats.freePages;

    if (pageCount <= 0) {
      return 0;
    }

    for (int i = 0; i < pageCount; i++) {
      CommitLock.Shared shared = mCommitLock.acquireShared();
      try {
        mPageManager.allocAndRecyclePage();
      } catch (Throwable e) {
        throw closeOnFailure(e);
      } finally {
        shared.release();
      }
    }

    return pageCount;
  }