diff options
author | B. Stack <bgstack15@gmail.com> | 2023-11-27 10:33:00 -0500 |
---|---|---|
committer | B. Stack <bgstack15@gmail.com> | 2023-11-27 10:33:00 -0500 |
commit | 2e61b9b6258f29c03cb3b0da48282f3a87590702 (patch) | |
tree | 2be66dfaf965d246ea2df6248c7890208887e6bb /zen | |
parent | add upstream 13.1 (diff) | |
download | FreeFileSync-2e61b9b6258f29c03cb3b0da48282f3a87590702.tar.gz FreeFileSync-2e61b9b6258f29c03cb3b0da48282f3a87590702.tar.bz2 FreeFileSync-2e61b9b6258f29c03cb3b0da48282f3a87590702.zip |
add upstream 13.213.2
Diffstat (limited to 'zen')
-rw-r--r-- | zen/file_access.cpp | 3 | ||||
-rw-r--r-- | zen/legacy_compiler.h | 3 | ||||
-rw-r--r-- | zen/serialize.h | 9 | ||||
-rw-r--r-- | zen/thread.h | 8 |
4 files changed, 17 insertions, 6 deletions
diff --git a/zen/file_access.cpp b/zen/file_access.cpp index 6a8a36da..22129157 100644 --- a/zen/file_access.cpp +++ b/zen/file_access.cpp @@ -349,9 +349,6 @@ void zen::moveAndRenameItem(const Zstring& pathFrom, const Zstring& pathTo, bool } } - - - namespace { void setWriteTimeNative(const Zstring& itemPath, const timespec& modTime, ProcSymlink procSl) //throw FileError diff --git a/zen/legacy_compiler.h b/zen/legacy_compiler.h index fce7fd7d..54909b71 100644 --- a/zen/legacy_compiler.h +++ b/zen/legacy_compiler.h @@ -40,6 +40,9 @@ basic_string<Char, Traits, Alloc> operator+(basic_string<Char, Traits, Alloc>&& } //--------------------------------------------------------------------------------- +//support for std::string::resize_and_overwrite() + #define ZEN_HAVE_RESIZE_AND_OVERWRITE 1 + namespace zen { double fromChars(const char* first, const char* last); diff --git a/zen/serialize.h b/zen/serialize.h index f3e4f7ff..82ea9971 100644 --- a/zen/serialize.h +++ b/zen/serialize.h @@ -260,6 +260,10 @@ BinContainer unbufferedLoad(Function tryRead /*(void* buffer, size_t bytesToRead BinContainer buf; for (;;) { +#ifndef ZEN_HAVE_RESIZE_AND_OVERWRITE +#error include legacy_compiler.h! +#endif +#if ZEN_HAVE_RESIZE_AND_OVERWRITE //permature(?) perf optimization; avoid needless zero-initialization: size_t bytesRead = 0; buf.resize_and_overwrite(buf.size() + blockSize, [&, bufSizeOld = buf.size()](char* rawBuf, size_t /*rawBufSize: caveat: may be larger than what's requested*/) //permature(?) perf optimization; avoid needless zero-initialization: @@ -267,6 +271,11 @@ BinContainer unbufferedLoad(Function tryRead /*(void* buffer, size_t bytesToRead bytesRead = tryRead(rawBuf + bufSizeOld, blockSize); //throw X; may return short; only 0 means EOF return bufSizeOld + bytesRead; }); +#else + buf.resize(buf.size() + blockSize); //needless zero-initialization! + const size_t bytesRead = tryRead(buf.data() + buf.size() - blockSize, blockSize); //throw X; may return short; only 0 means EOF + buf.resize(buf.size() - blockSize + bytesRead); //caveat: unsigned arithmetics +#endif if (bytesRead == 0) //end of file { //caveat: memory consumption of returned string! diff --git a/zen/thread.h b/zen/thread.h index 27b4c9b8..27e23b4a 100644 --- a/zen/thread.h +++ b/zen/thread.h @@ -203,10 +203,13 @@ public: //non-blocking wait()-alternative: context of controlling thread: void notifyWhenDone(const std::function<void()>& onCompletion /*noexcept! runs on worker thread!*/) { - std::lock_guard dummy(workLoad_.ref().lock); + std::unique_lock dummy(workLoad_.ref().lock); if (workLoad_.ref().tasksPending == 0) + { + dummy.unlock(); onCompletion(); + } else workLoad_.ref().onCompletionCallbacks.push_back(onCompletion); } @@ -242,8 +245,7 @@ private: if (--(workLoad.tasksPending) == 0) if (!workLoad.onCompletionCallbacks.empty()) { - std::vector<std::function<void()>> callbacks; - callbacks.swap(workLoad.onCompletionCallbacks); + std::vector<std::function<void()>> callbacks = std::exchange(workLoad.onCompletionCallbacks, {}); dummy.unlock(); for (const auto& cb : callbacks) |