filehash/ffdb_pagepool.c
int
ffdb_pagepool_delete (ffdb_pagepool_t* pgp, void* mem)
{
  struct _ffdb_hqh* head;
  ffdb_bkt_t* bp;
  int ret = 0;

  /* I have to lock this routine to prevent race condition
   * to ffdb_pagepool_find
   */
  FFDB_LOCK(pgp->lock);

  /* first get the page bucket pointer of this memory */
  bp = (ffdb_bkt_t *)((char *)mem - sizeof(ffdb_bkt_t));

  /* only thread holding this page can delete this page, and no other
   * threads waiting on this page 
   */
  head = &pgp->hqh[FFDB_HASHKEY(bp->pgno)];

  if (bp->ref == 1) {
    /* sanity check: page pin flag must be set */
    if (!FFDB_FLAG_ISSET(bp->flags, FFDB_PAGE_PINNED)) {
      fprintf (stderr, "ffdb_pagepool_delete: this page is not pinned\n");
      abort ();
    }

    /* if there are waiters, we cannot delete this page we need put
     */
    if (bp->waiters > 0) {
      fprintf (stderr, "ffdb_pagepool_delete: page %d has waiters\n",bp->pgno);
      FFDB_UNLOCK(pgp->lock);
      return EAGAIN;
    }
    
    /* Check whether this page is dirty. If it is , flush to disk */
    if (FFDB_FLAG_ISSET(bp->flags, FFDB_PAGE_DIRTY)) {
      if (_ffdb_pagepool_write (pgp, bp) != 0) {
	fprintf (stderr, "ffdb_pagepool_delete: page %d is dirty and flush it to disk encountered error.\n", bp->pgno);
	FFDB_UNLOCK(pgp->lock);
	return errno;
      }
    }
    
    /* Remove from the hash and lru queues. */

    FFDB_CIRCLEQ_REMOVE(head, bp, hq);
    FFDB_CIRCLEQ_REMOVE(&pgp->lqh, bp, lq);

    /* Decrease number of pages in the cache */
    --pgp->curcache;

    FFDB_UNLOCK(pgp->lock);
    /* free memory */
    free(bp); 

  }
  else {
    fprintf (stderr, "ffdb_pagepool_delete: other threads are still using this page %d ref = %d\n", bp->pgno, bp->ref);

    FFDB_UNLOCK(pgp->lock);

    ret = -1;
  }
  return ret;
}
/**
 * Really delete page from cache. This is used either by internal
 * other routines or user knows this page is not used anymore
 * @param pgp cache page poll pointer
 * @param mem memory pointer of this page
 * @return 0 this page is deleted and memory is freed. Otherwise return -1
 */
Really delete page from cache. This is used either by internal
other routines or user knows this page is not used anymore
@param pgp cache page poll pointer
@param mem memory pointer of this page
@return 0 this page is deleted and memory is freed. Otherwise return -1
Really delete page from cache . This is used either by internal other routines or user knows this page is not used anymore @param pgp cache page poll pointer @param mem memory pointer of this page @return 0 this page is deleted and memory is freed . Otherwise return - 1
int
ffdb_pagepool_delete (ffdb_pagepool_t* pgp, void* mem)
{
  struct _ffdb_hqh* head;
  ffdb_bkt_t* bp;
  int ret = 0;
  FFDB_LOCK(pgp->lock);
  bp = (ffdb_bkt_t *)((char *)mem - sizeof(ffdb_bkt_t));
  head = &pgp->hqh[FFDB_HASHKEY(bp->pgno)];
  if (bp->ref == 1) {
    if (!FFDB_FLAG_ISSET(bp->flags, FFDB_PAGE_PINNED)) {
      fprintf (stderr, "ffdb_pagepool_delete: this page is not pinned\n");
      abort ();
    }
    if (bp->waiters > 0) {
      fprintf (stderr, "ffdb_pagepool_delete: page %d has waiters\n",bp->pgno);
      FFDB_UNLOCK(pgp->lock);
      return EAGAIN;
    }
    if (FFDB_FLAG_ISSET(bp->flags, FFDB_PAGE_DIRTY)) {
      if (_ffdb_pagepool_write (pgp, bp) != 0) {
	fprintf (stderr, "ffdb_pagepool_delete: page %d is dirty and flush it to disk encountered error.\n", bp->pgno);
	FFDB_UNLOCK(pgp->lock);
	return errno;
      }
    }
    FFDB_CIRCLEQ_REMOVE(head, bp, hq);
    FFDB_CIRCLEQ_REMOVE(&pgp->lqh, bp, lq);
    --pgp->curcache;
    FFDB_UNLOCK(pgp->lock);
    free(bp); 
  }
  else {
    fprintf (stderr, "ffdb_pagepool_delete: other threads are still using this page %d ref = %d\n", bp->pgno, bp->ref);
    FFDB_UNLOCK(pgp->lock);
    ret = -1;
  }
  return ret;
}
int ffdb_pagepool_delete ( ffdb_pagepool_t * pgp , void * mem ) { struct _ffdb_hqh * head ; ffdb_bkt_t * bp ; int ret = 0 ; FFDB_LOCK ( pgp -> lock ) ; bp = ( ffdb_bkt_t * ) ( ( char * ) mem - sizeof ( ffdb_bkt_t ) ) ; head = & pgp -> hqh [ FFDB_HASHKEY ( bp -> pgno ) ] ; if ( bp -> ref == 1 ) { if ( ! FFDB_FLAG_ISSET ( bp -> flags , FFDB_PAGE_PINNED ) ) { fprintf ( stderr , " \n " ) ; abort ( ) ; } if ( bp -> waiters > 0 ) { fprintf ( stderr , " \n " , bp -> pgno ) ; FFDB_UNLOCK ( pgp -> lock ) ; return EAGAIN ; } if ( FFDB_FLAG_ISSET ( bp -> flags , FFDB_PAGE_DIRTY ) ) { if ( _ffdb_pagepool_write ( pgp , bp ) != 0 ) { fprintf ( stderr , " \n " , bp -> pgno ) ; FFDB_UNLOCK ( pgp -> lock ) ; return errno ; } } FFDB_CIRCLEQ_REMOVE ( head , bp , hq ) ; FFDB_CIRCLEQ_REMOVE ( & pgp -> lqh , bp , lq ) ; -- pgp -> curcache ; FFDB_UNLOCK ( pgp -> lock ) ; free ( bp ) ; } else { fprintf ( stderr , " \n " , bp -> pgno , bp -> ref ) ; FFDB_UNLOCK ( pgp -> lock ) ; ret = -1 ; } return ret ; }
Really delete page from cache.
Really delete page from cache .
/* I have to lock this routine to prevent race condition
   * to ffdb_pagepool_find
   */ /* first get the page bucket pointer of this memory */ /* only thread holding this page can delete this page, and no other
   * threads waiting on this page 
   */ /* sanity check: page pin flag must be set */ /* if there are waiters, we cannot delete this page we need put
     */ /* Check whether this page is dirty. If it is , flush to disk */ /* Remove from the hash and lru queues. */ /* Decrease number of pages in the cache */ /* free memory */