From b81efa8f131578c97c5580c4c31ebb7198763aca Mon Sep 17 00:00:00 2001 From: Vladimir Glazounov Date: Wed, 21 Oct 2009 14:48:59 +0000 Subject: CWS-TOOLING: integrate CWS fwk123 2009-10-14 10:18:49 +0200 cd r276885 : #i99971# Use AttachThreadInput to force SetForegroundWindow 2009-10-14 08:56:20 +0200 mav r276881 : #i105476# let the allocated memory live long anough 2009-10-14 08:53:51 +0200 mav r276880 : #i105476# let ZipFile use mutex while creating the requested stream 2009-10-14 08:51:52 +0200 mav r276879 : #i105476# let buffered IO use mutex ( patch from MHU ) 2009-10-09 12:20:22 +0200 cd r276803 : #i99971# Use configuration to control window to front/focus handling 2009-10-09 12:19:22 +0200 cd r276802 : #i99971# New configuration item to force set focus and window to front for new document windows 2009-10-09 12:18:23 +0200 cd r276801 : #i99971# Introduction of a new show flag to force window to front 2009-10-06 11:04:16 +0200 ab r276695 : #i105386# Call xmlInitParser() before registering input callbacks --- sal/osl/unx/file.cxx | 45 +++++++++++++++++++++++++++++++++++++++++++-- sal/osl/w32/file.cxx | 43 ++++++++++++++++++++++++++++++++++++++++++- 2 files changed, 85 insertions(+), 3 deletions(-) (limited to 'sal/osl') diff --git a/sal/osl/unx/file.cxx b/sal/osl/unx/file.cxx index b69849a08cdc..8e7d76cda614 100644 --- a/sal/osl/unx/file.cxx +++ b/sal/osl/unx/file.cxx @@ -44,6 +44,7 @@ #include #include +#include #include #if defined(MACOSX) @@ -74,8 +75,9 @@ ******************************************************************/ struct FileHandle_Impl { - rtl_String * m_strFilePath; /* holds native file path */ - int m_fd; + pthread_mutex_t m_mutex; + rtl_String * m_strFilePath; /* holds native file path */ + int m_fd; /** State */ @@ -169,6 +171,17 @@ struct FileHandle_Impl Allocator(); ~Allocator(); }; + + /** Guard. + */ + class Guard + { + pthread_mutex_t * m_mutex; + + public: + explicit Guard(pthread_mutex_t * pMutex); + ~Guard(); + }; }; /******************************************************************* @@ -213,6 +226,18 @@ void FileHandle_Impl::Allocator::deallocate (sal_uInt8 * pBuffer) rtl_cache_free (m_cache, pBuffer); } +FileHandle_Impl::Guard::Guard(pthread_mutex_t * pMutex) + : m_mutex (pMutex) +{ + OSL_PRECOND (m_mutex != 0, "FileHandle_Impl::Guard::Guard(): null pointer."); + (void) pthread_mutex_lock (m_mutex); // ignoring EINVAL ... +} +FileHandle_Impl::Guard::~Guard() +{ + OSL_PRECOND (m_mutex != 0, "FileHandle_Impl::Guard::~Guard(): null pointer."); + (void) pthread_mutex_unlock (m_mutex); +} + FileHandle_Impl::FileHandle_Impl (int fd, char const * path) : m_strFilePath (0), m_fd (fd), @@ -225,6 +250,7 @@ FileHandle_Impl::FileHandle_Impl (int fd, char const * path) m_bufsiz (0), m_buffer (0) { + (void) pthread_mutex_init(&m_mutex, 0); rtl_string_newFromStr (&m_strFilePath, path); Allocator::get().allocate (&m_buffer, &m_bufsiz); if (0 != m_buffer) @@ -234,6 +260,7 @@ FileHandle_Impl::~FileHandle_Impl() { Allocator::get().deallocate (m_buffer), m_buffer = 0; rtl_string_release (m_strFilePath), m_strFilePath = 0; + (void) pthread_mutex_destroy(&m_mutex); // ignoring EBUSY ... } void* FileHandle_Impl::operator new (size_t n) @@ -948,6 +975,8 @@ SAL_CALL osl_closeFile( oslFileHandle Handle ) if ((pImpl == 0) || (pImpl->m_fd < 0)) return osl_File_E_INVAL; + (void) pthread_mutex_lock (&(pImpl->m_mutex)); + /* close(2) implicitly (and unconditionally) unlocks */ OSL_TRACE("osl_closeFile(%d) => %s", pImpl->m_fd, rtl_string_getStr(pImpl->m_strFilePath)); oslFileError result = pImpl->syncFile(); @@ -962,6 +991,7 @@ SAL_CALL osl_closeFile( oslFileHandle Handle ) result = oslTranslateFileError (OSL_FET_ERROR, errno); } + (void) pthread_mutex_unlock (&(pImpl->m_mutex)); delete pImpl; return (result); } @@ -977,6 +1007,8 @@ SAL_CALL osl_syncFile(oslFileHandle Handle) if ((0 == pImpl) || (-1 == pImpl->m_fd)) return osl_File_E_INVAL; + FileHandle_Impl::Guard lock (&(pImpl->m_mutex)); + OSL_FILE_TRACE("osl_syncFile(%d)", pImpl->m_fd); oslFileError result = pImpl->syncFile(); if (result != osl_File_E_None) @@ -1086,6 +1118,7 @@ SAL_CALL osl_readLine ( sal_uInt64 uBytesRead = 0; // read at current fileptr; fileptr += uBytesRead; + FileHandle_Impl::Guard lock (&(pImpl->m_mutex)); oslFileError result = pImpl->readLineAt ( pImpl->m_fileptr, ppSequence, &uBytesRead); if (result == osl_File_E_None) @@ -1114,6 +1147,7 @@ SAL_CALL osl_readFile ( size_t const nBytesRequested = sal::static_int_cast< size_t >(uBytesRequested); // read at current fileptr; fileptr += *pBytesRead; + FileHandle_Impl::Guard lock (&(pImpl->m_mutex)); oslFileError result = pImpl->readFileAt ( pImpl->m_fileptr, pBuffer, nBytesRequested, pBytesRead); if (result == osl_File_E_None) @@ -1144,6 +1178,7 @@ SAL_CALL osl_writeFile ( size_t const nBytesToWrite = sal::static_int_cast< size_t >(uBytesToWrite); // write at current fileptr; fileptr += *pBytesWritten; + FileHandle_Impl::Guard lock (&(pImpl->m_mutex)); oslFileError result = pImpl->writeFileAt ( pImpl->m_fileptr, pBuffer, nBytesToWrite, pBytesWritten); if (result == osl_File_E_None) @@ -1180,6 +1215,7 @@ SAL_CALL osl_readFileAt ( size_t const nBytesRequested = sal::static_int_cast< size_t >(uBytesRequested); // read at specified fileptr + FileHandle_Impl::Guard lock (&(pImpl->m_mutex)); return pImpl->readFileAt (nOffset, pBuffer, nBytesRequested, pBytesRead); } @@ -1214,6 +1250,7 @@ SAL_CALL osl_writeFileAt ( size_t const nBytesToWrite = sal::static_int_cast< size_t >(uBytesToWrite); // write at specified fileptr + FileHandle_Impl::Guard lock (&(pImpl->m_mutex)); return pImpl->writeFileAt (nOffset, pBuffer, nBytesToWrite, pBytesWritten); } @@ -1228,6 +1265,7 @@ SAL_CALL osl_isEndOfFile( oslFileHandle Handle, sal_Bool *pIsEOF ) if ((0 == pImpl) || (-1 == pImpl->m_fd) || (0 == pIsEOF)) return osl_File_E_INVAL; + FileHandle_Impl::Guard lock (&(pImpl->m_mutex)); *pIsEOF = (pImpl->getPos() == pImpl->getSize()); return osl_File_E_None; } @@ -1243,6 +1281,7 @@ SAL_CALL osl_getFilePos( oslFileHandle Handle, sal_uInt64* pPos ) if ((0 == pImpl) || (-1 == pImpl->m_fd) || (0 == pPos)) return osl_File_E_INVAL; + FileHandle_Impl::Guard lock (&(pImpl->m_mutex)); *pPos = pImpl->getPos(); return osl_File_E_None; } @@ -1263,6 +1302,7 @@ SAL_CALL osl_setFilePos (oslFileHandle Handle, sal_uInt32 uHow, sal_Int64 uOffse return osl_File_E_OVERFLOW; off_t nPos = 0, nOffset = sal::static_int_cast< off_t >(uOffset); + FileHandle_Impl::Guard lock (&(pImpl->m_mutex)); switch(uHow) { case osl_Pos_Absolut: @@ -1304,6 +1344,7 @@ SAL_CALL osl_getFileSize( oslFileHandle Handle, sal_uInt64* pSize ) if ((0 == pImpl) || (-1 == pImpl->m_fd) || (0 == pSize)) return osl_File_E_INVAL; + FileHandle_Impl::Guard lock (&(pImpl->m_mutex)); *pSize = pImpl->getSize(); return osl_File_E_None; } diff --git a/sal/osl/w32/file.cxx b/sal/osl/w32/file.cxx index d2eb9e7a4523..34deba2293da 100644 --- a/sal/osl/w32/file.cxx +++ b/sal/osl/w32/file.cxx @@ -69,7 +69,8 @@ //################################################################## struct FileHandle_Impl { - HANDLE m_hFile; + CRITICAL_SECTION m_mutex; + HANDLE m_hFile; /** State */ @@ -162,6 +163,17 @@ struct FileHandle_Impl Allocator(); ~Allocator(); }; + + /** Guard. + */ + class Guard + { + LPCRITICAL_SECTION m_mutex; + + public: + explicit Guard(LPCRITICAL_SECTION pMutex); + ~Guard(); + }; }; FileHandle_Impl::Allocator & @@ -199,6 +211,18 @@ void FileHandle_Impl::Allocator::deallocate (sal_uInt8 * pBuffer) rtl_cache_free (m_cache, pBuffer); } +FileHandle_Impl::Guard::Guard(LPCRITICAL_SECTION pMutex) + : m_mutex (pMutex) +{ + OSL_PRECOND (m_mutex != 0, "FileHandle_Impl::Guard::Guard(): null pointer."); + ::EnterCriticalSection (m_mutex); +} +FileHandle_Impl::Guard::~Guard() +{ + OSL_PRECOND (m_mutex != 0, "FileHandle_Impl::Guard::~Guard(): null pointer."); + ::LeaveCriticalSection (m_mutex); +} + FileHandle_Impl::FileHandle_Impl(HANDLE hFile) : m_hFile (hFile), m_state (STATE_READABLE | STATE_WRITEABLE), @@ -210,6 +234,7 @@ FileHandle_Impl::FileHandle_Impl(HANDLE hFile) m_bufsiz (0), m_buffer (0) { + ::InitializeCriticalSection (&m_mutex); Allocator::get().allocate (&m_buffer, &m_bufsiz); if (m_buffer != 0) memset (m_buffer, 0, m_bufsiz); @@ -218,6 +243,7 @@ FileHandle_Impl::FileHandle_Impl(HANDLE hFile) FileHandle_Impl::~FileHandle_Impl() { Allocator::get().deallocate (m_buffer), m_buffer = 0; + ::DeleteCriticalSection (&m_mutex); } void * FileHandle_Impl::operator new(size_t n) @@ -729,6 +755,8 @@ SAL_CALL osl_syncFile(oslFileHandle Handle) if ((0 == pImpl) || !IsValidHandle(pImpl->m_hFile)) return osl_File_E_INVAL; + FileHandle_Impl::Guard lock (&(pImpl->m_mutex)); + oslFileError result = pImpl->syncFile(); if (result != osl_File_E_None) return result; @@ -747,6 +775,8 @@ SAL_CALL osl_closeFile(oslFileHandle Handle) if ((0 == pImpl) || !IsValidHandle(pImpl->m_hFile)) return osl_File_E_INVAL; + ::EnterCriticalSection (&(pImpl->m_mutex)); + oslFileError result = pImpl->syncFile(); if (result != osl_File_E_None) { @@ -759,6 +789,7 @@ SAL_CALL osl_closeFile(oslFileHandle Handle) result = oslTranslateFileError( GetLastError() ); } + ::LeaveCriticalSection (&(pImpl->m_mutex)); delete pImpl; return (result); } @@ -870,6 +901,7 @@ SAL_CALL osl_readLine( sal_uInt64 uBytesRead = 0; // read at current filepos; filepos += uBytesRead; + FileHandle_Impl::Guard lock (&(pImpl->m_mutex)); oslFileError result = pImpl->readLineAt ( pImpl->m_filepos, ppSequence, &uBytesRead); if (result == osl_File_E_None) @@ -890,6 +922,7 @@ SAL_CALL osl_readFile( return osl_File_E_INVAL; // read at current filepos; filepos += *pBytesRead; + FileHandle_Impl::Guard lock (&(pImpl->m_mutex)); oslFileError result = pImpl->readFileAt ( pImpl->m_filepos, pBuffer, uBytesRequested, pBytesRead); if (result == osl_File_E_None) @@ -911,6 +944,7 @@ SAL_CALL osl_writeFile( return osl_File_E_INVAL; // write at current filepos; filepos += *pBytesWritten; + FileHandle_Impl::Guard lock (&(pImpl->m_mutex)); oslFileError result = pImpl->writeFileAt ( pImpl->m_filepos, pBuffer, uBytesToWrite, pBytesWritten); if (result == osl_File_E_None) @@ -940,6 +974,7 @@ SAL_CALL osl_readFileAt( LONGLONG const nOffset = sal::static_int_cast< LONGLONG >(uOffset); // read at specified fileptr + FileHandle_Impl::Guard lock (&(pImpl->m_mutex)); return pImpl->readFileAt (nOffset, pBuffer, uBytesRequested, pBytesRead); } @@ -965,6 +1000,7 @@ SAL_CALL osl_writeFileAt( LONGLONG const nOffset = sal::static_int_cast< LONGLONG >(uOffset); // write at specified fileptr + FileHandle_Impl::Guard lock (&(pImpl->m_mutex)); return pImpl->writeFileAt (nOffset, pBuffer, uBytesToWrite, pBytesWritten); } @@ -977,6 +1013,7 @@ SAL_CALL osl_isEndOfFile (oslFileHandle Handle, sal_Bool *pIsEOF) if ((0 == pImpl) || !IsValidHandle(pImpl->m_hFile) || (0 == pIsEOF)) return osl_File_E_INVAL; + FileHandle_Impl::Guard lock (&(pImpl->m_mutex)); *pIsEOF = (pImpl->getPos() == pImpl->getSize()); return osl_File_E_None; } @@ -989,6 +1026,7 @@ SAL_CALL osl_getFilePos(oslFileHandle Handle, sal_uInt64 *pPos) if ((0 == pImpl) || !IsValidHandle(pImpl->m_hFile) || (0 == pPos)) return osl_File_E_INVAL; + FileHandle_Impl::Guard lock (&(pImpl->m_mutex)); *pPos = pImpl->getPos(); return osl_File_E_None; } @@ -1006,6 +1044,7 @@ SAL_CALL osl_setFilePos(oslFileHandle Handle, sal_uInt32 uHow, sal_Int64 uOffset return osl_File_E_OVERFLOW; LONGLONG nPos = 0, nOffset = sal::static_int_cast< LONGLONG >(uOffset); + FileHandle_Impl::Guard lock (&(pImpl->m_mutex)); switch (uHow) { case osl_Pos_Absolut: @@ -1045,6 +1084,7 @@ SAL_CALL osl_getFileSize (oslFileHandle Handle, sal_uInt64 *pSize) if ((0 == pImpl) || !IsValidHandle(pImpl->m_hFile) || (0 == pSize)) return osl_File_E_INVAL; + FileHandle_Impl::Guard lock (&(pImpl->m_mutex)); *pSize = pImpl->getSize(); return osl_File_E_None; } @@ -1064,6 +1104,7 @@ SAL_CALL osl_setFileSize (oslFileHandle Handle, sal_uInt64 uSize) if (g_limit_longlong < uSize) return osl_File_E_OVERFLOW; + FileHandle_Impl::Guard lock (&(pImpl->m_mutex)); oslFileError result = pImpl->syncFile(); if (result != osl_File_E_None) return (result); -- cgit