Ejemplo n.º 1
0
void rwb_uninitialize(FAR struct rwbuffer_s *rwb)
{
#ifdef CONFIG_DRVR_WRITEBUFFER
  if (rwb->wrmaxblocks > 0)
    {
      rwb_wrcanceltimeout(rwb);
      sem_destroy(&rwb->wrsem);
      if (rwb->wrbuffer)
        {
          kmm_free(rwb->wrbuffer);
        }
    }
#endif

#ifdef CONFIG_DRVR_READAHEAD
  if (rhmaxblocks > 0)
    {
      sem_destroy(&rwb->rhsem);
      if (rwb->rhbuffer)
        {
          kmm_free(rwb->rhbuffer);
        }
    }
#endif
}
Ejemplo n.º 2
0
static ssize_t rwb_writebuffer(FAR struct rwbuffer_s *rwb,
                               off_t startblock, uint32_t nblocks,
                               FAR const uint8_t *wrbuffer)
{
  int ret;

  /* Write writebuffer Logic */

  rwb_wrcanceltimeout(rwb);

  /* First: Should we flush out our cache? We would do that if (1) we already
   * buffering blocks and the next block writing is not in the same sequence,
   * or (2) the number of blocks would exceed our allocated buffer capacity
   */

  if (((startblock != rwb->wrexpectedblock) && (rwb->wrnblocks)) ||
      ((rwb->wrnblocks + nblocks) > rwb->wrmaxblocks))
    {
      fvdbg("writebuffer miss, expected: %08x, given: %08x\n",
            rwb->wrexpectedblock, startblock);

      /* Flush the write buffer */

      ret = rwb->wrflush(rwb, rwb->wrbuffer, rwb->wrblockstart, rwb->wrnblocks);
      if (ret < 0)
        {
          fdbg("ERROR: Error writing multiple from cache: %d\n", -ret);
          return ret;
        }

      rwb_resetwrbuffer(rwb);
    }

  /* writebuffer is empty? Then initialize it */

  if (rwb->wrnblocks == 0)
    {
      fvdbg("Fresh cache starting at block: 0x%08x\n", startblock);
      rwb->wrblockstart = startblock;
    }

  /* Add data to cache */

  fvdbg("writebuffer: copying %d bytes from %p to %p\n",
        nblocks * rwb->blocksize, wrbuffer,
        &rwb->wrbuffer[rwb->wrnblocks * rwb->blocksize]);
  memcpy(&rwb->wrbuffer[rwb->wrnblocks * rwb->blocksize],
         wrbuffer, nblocks * rwb->blocksize);

  rwb->wrnblocks      += nblocks;
  rwb->wrexpectedblock = rwb->wrblockstart + rwb->wrnblocks;
  rwb_wrstarttimeout(rwb);
  return nblocks;
}
Ejemplo n.º 3
0
void rwb_uninitialize(FAR struct rwbuffer_s *rwb)
{
#ifdef CONFIG_FS_WRITEBUFFER
    rwb_wrcanceltimeout(rwb);
    sem_destroy(&rwb->wrsem);
    if (rwb->wrbuffer)
    {
        kfree(rwb->wrbuffer);
    }
#endif

#ifdef CONFIG_FS_READAHEAD
    sem_destroy(&rwb->rhsem);
    if (rwb->rhbuffer)
    {
        kfree(rwb->rhbuffer);
    }
#endif
}