filehash/ffdb_pagepool.c
static int
_ffdb_pagepool_sync_i (ffdb_pagepool_t* pgp, unsigned int numpages)
{
  unsigned int num;
  ffdb_bkt_t* bp;
  ffdb_sbkt_t* sbp;
  ffdb_sbkt_t* next;
  ffdb_slh_t slh;
  FFDB_SLIST_INIT (&slh);

  /* Walk through every bucket and check whether it is pinned
   * If it is not pinned and it is dirty, I will sort these pages
   * according to page number
   */
  num = 0;
  FFDB_CIRCLEQ_FOREACH(bp, &pgp->lqh, lq){
    if (!FFDB_FLAG_ISSET(bp->flags, FFDB_PAGE_PINNED) &&
	bp->waiters == 0 && 
	FFDB_FLAG_ISSET(bp->flags, FFDB_PAGE_DIRTY)) {
      /* insert this bucket into a single linked list */
      sbp = (ffdb_sbkt_t *)malloc(sizeof(ffdb_sbkt_t));
      if (!sbp) {
	fprintf (stderr, "ffdb_pagepool_sync: cannot allocate space for single list element.\n");
	abort ();
      }
      _ffdb_shallow_copy_bk (sbp, bp);
      /* add this to the list */
      FFDB_SLIST_INSERT_HEAD (&slh, sbp, sl);
      num++;
      if (numpages > 0 && num >= numpages)
	break;
    }
  }

#ifdef _FFDB_DEBUG
  fprintf (stderr, "Flushed %d pages out\n", num);
#endif

  /* Do a merge sort on the list slh according to pageno */
  _ffdb_slist_merge_sort (&slh);

  /* Now walk through the sorted list, and dump pages to the back end file */
  sbp = FFDB_SLIST_FIRST(&slh);
  next = 0;
  while (sbp) {
    next = FFDB_SLIST_NEXT(sbp, sl);

    if (FFDB_FLAG_ISSET(sbp->bp->flags, FFDB_PAGE_DIRTY)) {

      if (_ffdb_pagepool_write (pgp, sbp->bp) != 0) {
	fprintf (stderr, "ffdb_pagepool_sync: writing page %d error.\n",
		 sbp->bp->pgno);
	return -1;
      }
    }
#ifdef _FFDB_STATISTICS
    ++pgp->pageflush;
#endif
    
    /* Free memory of each simple bucket */
    free (sbp);
    sbp = next;
  }

  return 0;
}
/**
 * Flush number of pages to disk
 * If numpages == 0, flush all dirty pages to disk
 */
Flush number of pages to disk
If numpages == 0, flush all dirty pages to disk
Flush number of pages to disk If numpages == 0 flush all dirty pages to disk
static int
_ffdb_pagepool_sync_i (ffdb_pagepool_t* pgp, unsigned int numpages)
{
  unsigned int num;
  ffdb_bkt_t* bp;
  ffdb_sbkt_t* sbp;
  ffdb_sbkt_t* next;
  ffdb_slh_t slh;
  FFDB_SLIST_INIT (&slh);
  num = 0;
  FFDB_CIRCLEQ_FOREACH(bp, &pgp->lqh, lq){
    if (!FFDB_FLAG_ISSET(bp->flags, FFDB_PAGE_PINNED) &&
	bp->waiters == 0 && 
	FFDB_FLAG_ISSET(bp->flags, FFDB_PAGE_DIRTY)) {
      sbp = (ffdb_sbkt_t *)malloc(sizeof(ffdb_sbkt_t));
      if (!sbp) {
	fprintf (stderr, "ffdb_pagepool_sync: cannot allocate space for single list element.\n");
	abort ();
      }
      _ffdb_shallow_copy_bk (sbp, bp);
      FFDB_SLIST_INSERT_HEAD (&slh, sbp, sl);
      num++;
      if (numpages > 0 && num >= numpages)
	break;
    }
  }
#ifdef _FFDB_DEBUG
  fprintf (stderr, "Flushed %d pages out\n", num);
#endif
  _ffdb_slist_merge_sort (&slh);
  sbp = FFDB_SLIST_FIRST(&slh);
  next = 0;
  while (sbp) {
    next = FFDB_SLIST_NEXT(sbp, sl);
    if (FFDB_FLAG_ISSET(sbp->bp->flags, FFDB_PAGE_DIRTY)) {
      if (_ffdb_pagepool_write (pgp, sbp->bp) != 0) {
	fprintf (stderr, "ffdb_pagepool_sync: writing page %d error.\n",
		 sbp->bp->pgno);
	return -1;
      }
    }
#ifdef _FFDB_STATISTICS
    ++pgp->pageflush;
#endif
    free (sbp);
    sbp = next;
  }
  return 0;
}
static int _ffdb_pagepool_sync_i ( ffdb_pagepool_t * pgp , unsigned int numpages ) { unsigned int num ; ffdb_bkt_t * bp ; ffdb_sbkt_t * sbp ; ffdb_sbkt_t * next ; ffdb_slh_t slh ; FFDB_SLIST_INIT ( & slh ) ; num = 0 ; FFDB_CIRCLEQ_FOREACH ( bp , & pgp -> lqh , lq ) { if ( ! FFDB_FLAG_ISSET ( bp -> flags , FFDB_PAGE_PINNED ) && bp -> waiters == 0 && FFDB_FLAG_ISSET ( bp -> flags , FFDB_PAGE_DIRTY ) ) { sbp = ( ffdb_sbkt_t * ) malloc ( sizeof ( ffdb_sbkt_t ) ) ; if ( ! sbp ) { fprintf ( stderr , " \n " ) ; abort ( ) ; } _ffdb_shallow_copy_bk ( sbp , bp ) ; FFDB_SLIST_INSERT_HEAD ( & slh , sbp , sl ) ; num ++ ; if ( numpages > 0 && num >= numpages ) break ; } } #ifdef _FFDB_DEBUG fprintf ( stderr , " \n " , num ) ; #endif _ffdb_slist_merge_sort ( & slh ) ; sbp = FFDB_SLIST_FIRST ( & slh ) ; next = 0 ; while ( sbp ) { next = FFDB_SLIST_NEXT ( sbp , sl ) ; if ( FFDB_FLAG_ISSET ( sbp -> bp -> flags , FFDB_PAGE_DIRTY ) ) { if ( _ffdb_pagepool_write ( pgp , sbp -> bp ) != 0 ) { fprintf ( stderr , " \n " , sbp -> bp -> pgno ) ; return -1 ; } } #ifdef _FFDB_STATISTICS ++ pgp -> pageflush ; #endif free ( sbp ) ; sbp = next ; } return 0 ; }
Flush number of pages to disk
 If numpages == 0, flush all dirty pages to disk
Flush number of pages to disk If numpages == 0 flush all dirty pages to disk
/* Walk through every bucket and check whether it is pinned
   * If it is not pinned and it is dirty, I will sort these pages
   * according to page number
   */ /* insert this bucket into a single linked list */ /* add this to the list */ /* Do a merge sort on the list slh according to pageno */ /* Now walk through the sorted list, and dump pages to the back end file */ /* Free memory of each simple bucket */