mirror of
https://github.com/apache/nuttx.git
synced 2026-06-01 07:45:16 +08:00
cosmetic
git-svn-id: svn://svn.code.sf.net/p/nuttx/code/trunk@2228 42af7a65-404d-4744-a932-0658087f49c3
This commit is contained in:
+43
-46
@@ -106,9 +106,8 @@ static void rwb_semtake(sem_t *sem)
|
|||||||
* Name: rwb_overlap
|
* Name: rwb_overlap
|
||||||
****************************************************************************/
|
****************************************************************************/
|
||||||
|
|
||||||
static inline boolean
|
static inline boolean rwb_overlap(off_t bufferstart1, size_t buffersize1,
|
||||||
rwb_overlap(off_t bufferstart1, size_t buffersize1,
|
off_t bufferstart2, size_t buffersize2)
|
||||||
off_t bufferstart2, size_t buffersize2)
|
|
||||||
{
|
{
|
||||||
off_t bufferend1 = bufferstart1 + buffersize1;
|
off_t bufferend1 = bufferstart1 + buffersize1;
|
||||||
off_t bufferend2 = bufferstart2 + buffersize2;
|
off_t bufferend2 = bufferstart2 + buffersize2;
|
||||||
@@ -156,15 +155,15 @@ static void rwb_wrflush(struct rwbuffer_s *rwb)
|
|||||||
if (rwb->wrnbytes)
|
if (rwb->wrnbytes)
|
||||||
{
|
{
|
||||||
fvdbg("Flushing: blockstart=0x%08lx nbytes=%d from buffer=%p",
|
fvdbg("Flushing: blockstart=0x%08lx nbytes=%d from buffer=%p",
|
||||||
(long)rwb->wrblockstart, (long)rwb->wrnbytes, (long)rwb->wrbuffer);
|
(long)rwb->wrblockstart, (long)rwb->wrnbytes, (long)rwb->wrbuffer);
|
||||||
|
|
||||||
/* Flush cache */
|
/* Flush cache */
|
||||||
|
|
||||||
ret = rwb->wrflush(rwb->dev, rwb->wrbuffer, rwb->wrblockstart, rwb->wrnbytes);
|
ret = rwb->wrflush(rwb->dev, rwb->wrbuffer, rwb->wrblockstart, rwb->wrnbytes);
|
||||||
if (ret < 0)
|
if (ret < 0)
|
||||||
{
|
{
|
||||||
fdbg("ERROR: Error flushing write buffer: %d\n", -ret);
|
fdbg("ERROR: Error flushing write buffer: %d\n", -ret);
|
||||||
}
|
}
|
||||||
|
|
||||||
rwb_resetwrbuffer(rwb);
|
rwb_resetwrbuffer(rwb);
|
||||||
}
|
}
|
||||||
@@ -237,16 +236,16 @@ static ssize_t rwb_writebuffer(FAR struct rwbuffer_s *rwb,
|
|||||||
((rwb->wrnbytes + nbytes) > rwb->wrallocsize))
|
((rwb->wrnbytes + nbytes) > rwb->wrallocsize))
|
||||||
{
|
{
|
||||||
fvdbg("writebuffer miss, expected: 0x%08x, given: 0x%08x",
|
fvdbg("writebuffer miss, expected: 0x%08x, given: 0x%08x",
|
||||||
rwb->wrexpectedblock, startblock);
|
rwb->wrexpectedblock, startblock);
|
||||||
|
|
||||||
/* Flush cache */
|
/* Flush cache */
|
||||||
|
|
||||||
ret = rwb->wrflush(rwb, rwb->wrbuffer, rwb->wrblockstart, rwb->wrnbytes);
|
ret = rwb->wrflush(rwb, rwb->wrbuffer, rwb->wrblockstart, rwb->wrnbytes);
|
||||||
if (ret < 0)
|
if (ret < 0)
|
||||||
{
|
{
|
||||||
fdbg("ERROR: Error writing multiple from cache: %d\n", -ret);
|
fdbg("ERROR: Error writing multiple from cache: %d\n", -ret);
|
||||||
return ret;
|
return ret;
|
||||||
}
|
}
|
||||||
|
|
||||||
rwb_resetwrbuffer(rwb);
|
rwb_resetwrbuffer(rwb);
|
||||||
}
|
}
|
||||||
@@ -308,7 +307,7 @@ rwb_bufferread(struct rwbuffer_s *rwb, off_t startblock,
|
|||||||
|
|
||||||
/* Get the byte address in the read-ahead buffer */
|
/* Get the byte address in the read-ahead buffer */
|
||||||
|
|
||||||
ubyte *pchBuffer = rwb->rhbuffer + dwStartByteOffset;
|
ubyte *pchBuffer = rwb->rhbuffer + dwStartByteOffset;
|
||||||
|
|
||||||
/* Copy the data from the read-ahead buffer into the IO buffer */
|
/* Copy the data from the read-ahead buffer into the IO buffer */
|
||||||
|
|
||||||
@@ -507,51 +506,51 @@ int rwb_read(FAR struct rwbuffer_s *rwb, off_t startblock, uint32 blockcount,
|
|||||||
/* Is there anything in the read-ahead buffer? */
|
/* Is there anything in the read-ahead buffer? */
|
||||||
|
|
||||||
if (rwb->rhnbytes > 0)
|
if (rwb->rhnbytes > 0)
|
||||||
{
|
{
|
||||||
off_t startblock = startblock;
|
off_t startblock = startblock;
|
||||||
size_t nblocks = 0;
|
size_t nblocks = 0;
|
||||||
off_t bufferend;
|
off_t bufferend;
|
||||||
|
|
||||||
/* Loop for each block we find in the read-head buffer. Count the
|
/* Loop for each block we find in the read-head buffer. Count the
|
||||||
* number of buffers that we can read from read-ahead buffer.
|
* number of buffers that we can read from read-ahead buffer.
|
||||||
*/
|
*/
|
||||||
|
|
||||||
bufferend = rwb->rhblockstart + rwb->rhnbytes;
|
bufferend = rwb->rhblockstart + rwb->rhnbytes;
|
||||||
|
|
||||||
while ((startblock >= rwb->rhblockstart) &&
|
while ((startblock >= rwb->rhblockstart) &&
|
||||||
(startblock < bufferend) &&
|
(startblock < bufferend) &&
|
||||||
(blockcount > 0))
|
(blockcount > 0))
|
||||||
{
|
{
|
||||||
/* This is one more that we will read from the read ahead buffer */
|
/* This is one more that we will read from the read ahead buffer */
|
||||||
|
|
||||||
nblocks++;
|
nblocks++;
|
||||||
|
|
||||||
/* And one less that we will read from the media */
|
/* And one less that we will read from the media */
|
||||||
|
|
||||||
startblock++;
|
startblock++;
|
||||||
blockcount--;
|
blockcount--;
|
||||||
}
|
}
|
||||||
|
|
||||||
/* Then read the data from the read-ahead buffer */
|
/* Then read the data from the read-ahead buffer */
|
||||||
|
|
||||||
rwb_bufferread(rwb, startblock,
|
rwb_bufferread(rwb, startblock, nblocks, &rdbuffer);
|
||||||
nblocks, &rdbuffer);
|
}
|
||||||
}
|
|
||||||
|
|
||||||
/* If we did not get all of the data from the buffer, then we have to refill
|
/* If we did not get all of the data from the buffer, then we have to refill
|
||||||
* the buffer and try again.
|
* the buffer and try again.
|
||||||
*/
|
*/
|
||||||
|
|
||||||
if (blockcount > 0)
|
if (blockcount > 0)
|
||||||
{
|
{
|
||||||
int ret = rwb_rhreload(rwb, startblock);
|
int ret = rwb_rhreload(rwb, startblock);
|
||||||
if (ret < 0)
|
if (ret < 0)
|
||||||
{
|
{
|
||||||
fdbg("ERROR: Failed to fill the read-ahead buffer: %d", -ret);
|
fdbg("ERROR: Failed to fill the read-ahead buffer: %d", -ret);
|
||||||
return ret;
|
return ret;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
rwb_semgive(&rwb->rhsem);
|
rwb_semgive(&rwb->rhsem);
|
||||||
return 0;
|
return 0;
|
||||||
#else
|
#else
|
||||||
@@ -576,9 +575,7 @@ int rwb_write(FAR struct rwbuffer_s *rwb, off_t startblock,
|
|||||||
*/
|
*/
|
||||||
|
|
||||||
rwb_semtake(&rwb->rhsem);
|
rwb_semtake(&rwb->rhsem);
|
||||||
if (rwb_overlap(rwb->rhblockstart,
|
if (rwb_overlap(rwb->rhblockstart, rwb->rhnbytes, startblock, blockcount))
|
||||||
rwb->rhnbytes,
|
|
||||||
startblock, blockcount))
|
|
||||||
{
|
{
|
||||||
rwb_resetrhbuffer(rwb);
|
rwb_resetrhbuffer(rwb);
|
||||||
}
|
}
|
||||||
@@ -588,7 +585,7 @@ int rwb_write(FAR struct rwbuffer_s *rwb, off_t startblock,
|
|||||||
#ifdef CONFIG_FS_WRITEBUFFER
|
#ifdef CONFIG_FS_WRITEBUFFER
|
||||||
fvdbg("startblock=%d wrbuffer=%p", startblock, wrbuffer);
|
fvdbg("startblock=%d wrbuffer=%p", startblock, wrbuffer);
|
||||||
|
|
||||||
/* Use the block cache unless the buffer size is bigger than block cache */
|
/* Use the block cache unless the buffer size is bigger than block cache */
|
||||||
|
|
||||||
if (blockcount > rwb->wrallocsize)
|
if (blockcount > rwb->wrallocsize)
|
||||||
{
|
{
|
||||||
|
|||||||
Reference in New Issue
Block a user