Exemplo n.º 1
0
gxDatabaseError BtreeCache::LRUFlush(unsigned num_to_flush)
// Function used to flush a specified number of least recently
// used (LRU) dirty buckets. Returns zero if successful or a 
// non-zero value to indicate a failure.
{
  if((f == 0) || (buckets == 0)) return gxDBASE_NULL_PTR;

  // Flush, starting at the tail so that cache will be flushed
  // in a first in, first out sequence (FIFO)
  BtreeBucket *bucket = tail;

  unsigned num_flushed = 0;

  // PC-lint 04/20/2004: Possible use ot null pointer
  if(!bucket) return gxDBASE_NULL_PTR;

  while(1) {
    if(num_flushed == num_to_flush) break;
    if(f->ReadyForWriting()) {
      if(bucket->Flush(f) != gxDBASE_NO_ERROR) {
	return f->GetDatabaseError(); // Error writing to the file 
      }
    }
    else { // The file is not ready for writing
      return f->SetDatabaseError(gxDBASE_FILE_NOT_READY);
    }
    bucket = bucket->prev;
    if(bucket == tail) break; // Reached the end of the list
    num_flushed++;
  }

  return gxDBASE_NO_ERROR;
}
Exemplo n.º 2
0
gxDatabaseError BtreeCache::Flush()
// Function used to flush all the dirty buckets to the database file.
// Returns zero if successful or a non-zero value to indicate 
// a failure.
{
  if((f == 0) || (buckets == 0)) return gxDBASE_NULL_PTR;

  // Flush, starting at the front so that cache will be flushed
  // in a first in, last out sequence
  BtreeBucket *bucket = head;

  // PC-lint 04/20/2004: Possible use of null pointer
  if(!bucket) return gxDBASE_NULL_PTR;

  do {
    if(f->ReadyForWriting()) {
      if(bucket->Flush(f) != gxDBASE_NO_ERROR) {
	return f->GetDatabaseError(); // Error writing to the file 
      }
    }
    else { // The file is not ready for writing
      return f->SetDatabaseError(gxDBASE_FILE_NOT_READY);
    }

    bucket = bucket->next;
  } while(bucket != head);

  return gxDBASE_NO_ERROR;
}
Exemplo n.º 3
0
BtreeBucket *BtreeCache::FindEmptyBucket()
// Internal processing function used to find the last
// bucket in the cache that is empty and promote the
// bucket to the front of the list. Returns a pointer
// to the bucket or a null value if no buckets can be
// made available or an error occurs. For maximum speed
// performance the least-recently reserved bucket will 
// be always be flushed and re-allocated to prevent the 
// cache from filling up.
{
  if(IsEmpty()) {
    // Set the database error code here to ensure that an 
    // exception is properly signaled in the gxBtree
    // cached insert, delete, and find functions.
    if(f) f->SetDatabaseError(gxDBASE_CACHE_ERROR);
    return 0;
  }

  BtreeBucket *bucket = tail;

  // PC-lint 04/20/2004: Possible use of null pointer
  if(!bucket) return 0;

  if(f) { // PC-lint 04/20/2004: Possible use of null pointer
    if(f->ReadyForWriting()) {
      if(bucket->Flush(f) != gxDBASE_NO_ERROR) {
	return 0; // Error writing to the file 
      }
    }
    else { // The file is not ready for writing
      f->SetDatabaseError(gxDBASE_FILE_NOT_READY);
      return 0;
    }
  }

  PromoteBucket(bucket);
  return bucket;
}