Skip to content

Commit

Permalink
[win32] CLog: Do not use FlushFileBuffers after each write to file wh…
Browse files Browse the repository at this point in the history
…ich causes unnecessary performance penalties. Instead of using FlushFileBuffers specify FILE_FLAG_WRITE_THROUGH flag on the creation which causes any writes made to that handle to be written directly to the file without being buffered.
  • Loading branch information
Anton Fedchin committed Apr 20, 2015
1 parent 475e73b commit 76c3ea7
Showing 1 changed file with 3 additions and 2 deletions.
5 changes: 3 additions & 2 deletions xbmc/utils/win32/Win32InterfaceForCLog.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -60,13 +60,15 @@ bool CWin32InterfaceForCLog::OpenLogFile(const std::string& logFilename, const s
}

m_hFile = CreateFileW(strLogFileW.c_str(), GENERIC_WRITE, FILE_SHARE_READ, NULL,
CREATE_ALWAYS, FILE_ATTRIBUTE_NORMAL, NULL);
CREATE_ALWAYS, FILE_ATTRIBUTE_NORMAL | FILE_FLAG_WRITE_THROUGH, NULL);

if (m_hFile == INVALID_HANDLE_VALUE)
return false;

static const unsigned char BOM[3] = { 0xEF, 0xBB, 0xBF };
DWORD written;
(void)WriteFile(m_hFile, BOM, sizeof(BOM), &written, NULL); // write BOM, ignore possible errors
(void)FlushFileBuffers(m_hFile);

return true;
}
Expand All @@ -91,7 +93,6 @@ bool CWin32InterfaceForCLog::WriteStringToLog(const std::string& logString)

DWORD written;
const bool ret = (WriteFile(m_hFile, strData.c_str(), strData.length(), &written, NULL) != 0) && written == strData.length();
(void)FlushFileBuffers(m_hFile);

return ret;
}
Expand Down

0 comments on commit 76c3ea7

Please sign in to comment.