diff options
author | Daniel Wilhelm <daniel@wili.li> | 2014-04-18 17:20:07 +0200 |
---|---|---|
committer | Daniel Wilhelm <daniel@wili.li> | 2014-04-18 17:20:07 +0200 |
commit | 88a8b528e20013c0aa3cc6bcd9659b0b5ddd9170 (patch) | |
tree | c6c5babb49b90293380106b81ae5c446959ac70f /lib/binary.cpp | |
parent | 5.3 (diff) | |
download | FreeFileSync-88a8b528e20013c0aa3cc6bcd9659b0b5ddd9170.tar.gz FreeFileSync-88a8b528e20013c0aa3cc6bcd9659b0b5ddd9170.tar.bz2 FreeFileSync-88a8b528e20013c0aa3cc6bcd9659b0b5ddd9170.zip |
5.4
Diffstat (limited to 'lib/binary.cpp')
-rw-r--r-- | lib/binary.cpp | 42 |
1 files changed, 27 insertions, 15 deletions
diff --git a/lib/binary.cpp b/lib/binary.cpp index c01bb4d2..4fc1d408 100644 --- a/lib/binary.cpp +++ b/lib/binary.cpp @@ -5,12 +5,15 @@ // ************************************************************************** #include "binary.h" -#include <wx/stopwatch.h> +#include <zen/tick_count.h> #include <vector> #include <zen/file_io.h> #include <zen/int64.h> #include <boost/thread/tss.hpp> +using namespace zen; + + inline void setMinSize(std::vector<char>& buffer, size_t minSize) { @@ -61,6 +64,9 @@ private: size_t bufSize; }; + + +const std::int64_t TICKS_PER_SEC = ticksPerSec(); } @@ -80,33 +86,39 @@ bool zen::filesHaveSameContent(const Zstring& filename1, const Zstring& filename std::vector<char>& memory2 = *cpyBuf2; BufferSize bufferSize; - zen::UInt64 bytesCompared; + UInt64 bytesCompared; - wxLongLong lastDelayViolation = wxGetLocalTimeMillis(); + TickVal lastDelayViolation = getTicks(); do { setMinSize(memory1, bufferSize); setMinSize(memory2, bufferSize); - const wxLongLong startTime = wxGetLocalTimeMillis(); + const TickVal startTime = getTicks(); const size_t length1 = file1.read(&memory1[0], bufferSize); //returns actual number of bytes read; throw FileError() const size_t length2 = file2.read(&memory2[0], bufferSize); // - const wxLongLong stopTime = wxGetLocalTimeMillis(); + const TickVal stopTime = getTicks(); - //-------- dynamically set buffer size to keep callback interval between 200 - 500ms --------------------- - const wxLongLong loopTime = stopTime - startTime; - if (loopTime < 200 && stopTime - lastDelayViolation > 2000) //avoid "flipping back": e.g. DVD-Roms read 32MB at once, so first read may be > 300 ms, but second one will be 0ms! - { - lastDelayViolation = stopTime; - bufferSize.inc(); //practically no costs! - } - else if (loopTime > 500) + //-------- dynamically set buffer size to keep callback interval between 100 - 500ms --------------------- + if (TICKS_PER_SEC > 0) { - lastDelayViolation = stopTime; - bufferSize.dec(); // + const std::int64_t loopTime = (stopTime - startTime) * 1000 / TICKS_PER_SEC; //unit: [ms] + if (loopTime < 100) + { + if ((stopTime - lastDelayViolation) / TICKS_PER_SEC > 2) //avoid "flipping back": e.g. DVD-Roms read 32MB at once, so first read may be > 500 ms, but second one will be 0ms! + { + lastDelayViolation = stopTime; + bufferSize.inc(); + } + } + else if (loopTime > 500) + { + lastDelayViolation = stopTime; + bufferSize.dec(); + } } //------------------------------------------------------------------------------------------------ |