Enhanced Unix code for auto-extending files.
git-svn-id: https://svn.code.sf.net/p/flaim/code/trunk@653 0109f412-320b-0410-ab79-c3e0c5ffbbe6
This commit is contained in:
@@ -2754,6 +2754,7 @@ void F_FileHdl::initCommonData( void)
|
||||
m_bOpenedExclusive = FALSE;
|
||||
m_bOpenedInAsyncMode = FALSE;
|
||||
m_bDoDirectIO = FALSE;
|
||||
m_numAsyncPending = 0;
|
||||
}
|
||||
|
||||
/*****************************************************************************
|
||||
@@ -2761,6 +2762,8 @@ Desc:
|
||||
******************************************************************************/
|
||||
void F_FileHdl::freeCommonData( void)
|
||||
{
|
||||
f_assert( !m_numAsyncPending);
|
||||
|
||||
if( m_pucAlignedBuff)
|
||||
{
|
||||
f_freeAlignedBuffer( (void **)&m_pucAlignedBuff);
|
||||
@@ -3033,6 +3036,8 @@ RCODE F_FileAsyncClient::prepareForAsync(
|
||||
m_pIOBuffer->setPending();
|
||||
}
|
||||
|
||||
f_atomicInc( &m_pFileHdl->m_numAsyncPending);
|
||||
|
||||
Exit:
|
||||
|
||||
return( rc);
|
||||
@@ -3141,6 +3146,8 @@ void FLMAPI F_FileAsyncClient::notifyComplete(
|
||||
|
||||
if( m_pFileHdl)
|
||||
{
|
||||
f_assert( m_pFileHdl->m_numAsyncPending);
|
||||
f_atomicDec( &m_pFileHdl->m_numAsyncPending);
|
||||
m_pFileHdl->Release();
|
||||
m_pFileHdl = NULL;
|
||||
}
|
||||
@@ -3268,6 +3275,10 @@ RCODE F_FileHdl::directRead(
|
||||
{
|
||||
ui64ReadOffset = m_ui64CurrentPos;
|
||||
}
|
||||
else
|
||||
{
|
||||
m_ui64CurrentPos = ui64ReadOffset;
|
||||
}
|
||||
|
||||
// This loop does multiple reads (if necessary) to get all of the
|
||||
// data. It uses aligned buffers and reads at sector offsets.
|
||||
@@ -3423,6 +3434,10 @@ RCODE F_FileHdl::directWrite(
|
||||
{
|
||||
ui64WriteOffset = m_ui64CurrentPos;
|
||||
}
|
||||
else
|
||||
{
|
||||
m_ui64CurrentPos = ui64WriteOffset;
|
||||
}
|
||||
|
||||
if( pIOBuffer)
|
||||
{
|
||||
|
||||
@@ -3014,6 +3014,10 @@ RCODE F_FileHdl::lowLevelRead(
|
||||
{
|
||||
ui64ReadOffset = m_ui64CurrentPos;
|
||||
}
|
||||
else
|
||||
{
|
||||
m_ui64CurrentPos = ui64ReadOffset;
|
||||
}
|
||||
|
||||
if( !pvBuffer)
|
||||
{
|
||||
@@ -3335,6 +3339,10 @@ RCODE F_FileHdl::lowLevelWrite(
|
||||
{
|
||||
ui64WriteOffset = m_ui64CurrentPos;
|
||||
}
|
||||
else
|
||||
{
|
||||
m_ui64CurrentPos = ui64WriteOffset;
|
||||
}
|
||||
|
||||
if( !pvBuffer)
|
||||
{
|
||||
|
||||
@@ -768,6 +768,7 @@
|
||||
FLMBOOL m_bOpenedExclusive;
|
||||
FLMBOOL m_bDoDirectIO;
|
||||
FLMBOOL m_bOpenedInAsyncMode;
|
||||
FLMATOMIC m_numAsyncPending;
|
||||
|
||||
#if defined( FLM_WIN)
|
||||
HANDLE m_hFile;
|
||||
|
||||
@@ -480,6 +480,10 @@ RCODE F_FileHdl::lowLevelRead(
|
||||
{
|
||||
ui64ReadOffset = m_ui64CurrentPos;
|
||||
}
|
||||
else
|
||||
{
|
||||
m_ui64CurrentPos = ui64ReadOffset;
|
||||
}
|
||||
|
||||
if( !pvBuffer)
|
||||
{
|
||||
@@ -646,6 +650,7 @@ RCODE F_FileHdl::lowLevelWrite(
|
||||
FLMUINT uiBytesWritten = 0;
|
||||
F_FileAsyncClient * pAsyncClient = NULL;
|
||||
FLMBOOL bWaitForWrite = FALSE;
|
||||
FLMBYTE * pucExtendBuffer = NULL;
|
||||
|
||||
if( pIOBuffer && pvBuffer && pvBuffer != pIOBuffer->getBufferPtr())
|
||||
{
|
||||
@@ -657,8 +662,12 @@ RCODE F_FileHdl::lowLevelWrite(
|
||||
{
|
||||
ui64WriteOffset = m_ui64CurrentPos;
|
||||
}
|
||||
else
|
||||
{
|
||||
m_ui64CurrentPos = ui64WriteOffset;
|
||||
}
|
||||
|
||||
if( m_bDoDirectIO)
|
||||
if( m_bDoDirectIO && !m_numAsyncPending)
|
||||
{
|
||||
FLMUINT64 ui64CurrFileSize;
|
||||
FLMUINT uiTotalBytesToExtend;
|
||||
@@ -698,19 +707,25 @@ RCODE F_FileHdl::lowLevelWrite(
|
||||
|
||||
if( uiTotalBytesToExtend)
|
||||
{
|
||||
FLMUINT uiCurrBytesToExtend;
|
||||
FLMINT iBytesWritten;
|
||||
FLMUINT uiCurrBytesToExtend;
|
||||
FLMUINT uiExtendBufferSize;
|
||||
|
||||
f_memset( m_pucAlignedBuff, 0, m_uiAlignedBuffSize);
|
||||
uiExtendBufferSize = f_min( uiTotalBytesToExtend, 64 * 1024);
|
||||
|
||||
if( RC_BAD( rc = f_allocAlignedBuffer(
|
||||
uiExtendBufferSize, &pucExtendBuffer)))
|
||||
{
|
||||
goto Exit;
|
||||
}
|
||||
|
||||
while( uiTotalBytesToExtend)
|
||||
{
|
||||
uiCurrBytesToExtend = f_min(
|
||||
uiTotalBytesToExtend, m_uiAlignedBuffSize);
|
||||
uiTotalBytesToExtend, uiExtendBufferSize);
|
||||
|
||||
if( (iBytesWritten = pwrite( m_fd,
|
||||
m_pucAlignedBuff, uiCurrBytesToExtend,
|
||||
ui64CurrFileSize)) == -1)
|
||||
if( (iBytesWritten = pwrite( m_fd, pucExtendBuffer,
|
||||
uiCurrBytesToExtend, ui64CurrFileSize)) == -1)
|
||||
{
|
||||
if( errno == EINTR)
|
||||
{
|
||||
@@ -894,6 +909,11 @@ Exit:
|
||||
f_assert( RC_BAD( rc));
|
||||
pIOBuffer->notifyComplete( rc);
|
||||
}
|
||||
|
||||
if( pucExtendBuffer)
|
||||
{
|
||||
f_freeAlignedBuffer( &pucExtendBuffer);
|
||||
}
|
||||
|
||||
if( puiBytesWritten)
|
||||
{
|
||||
|
||||
@@ -339,6 +339,10 @@ RCODE F_FileHdl::lowLevelRead(
|
||||
{
|
||||
ui64ReadOffset = m_ui64CurrentPos;
|
||||
}
|
||||
else
|
||||
{
|
||||
m_ui64CurrentPos = ui64ReadOffset;
|
||||
}
|
||||
|
||||
if( !pvBuffer)
|
||||
{
|
||||
@@ -491,6 +495,10 @@ RCODE F_FileHdl::lowLevelWrite(
|
||||
{
|
||||
ui64WriteOffset = m_ui64CurrentPos;
|
||||
}
|
||||
else
|
||||
{
|
||||
m_ui64CurrentPos = ui64WriteOffset;
|
||||
}
|
||||
|
||||
if( m_bDoDirectIO)
|
||||
{
|
||||
|
||||
Reference in New Issue
Block a user