diff options
author | B3n30 <benediktthomas@gmail.com> | 2018-10-08 23:28:54 +0200 |
---|---|---|
committer | fearlessTobi <thm.frey@gmail.com> | 2019-02-15 22:14:54 +0100 |
commit | 2195f10d152a52e01ccab0a6528f8758752d66a9 (patch) | |
tree | 6bf2fb03d0df8224a44259eed4a773bc67fe4b45 | |
parent | threadsafe_queue: Add WaitIfEmpty and use it in logging (diff) | |
download | yuzu-2195f10d152a52e01ccab0a6528f8758752d66a9.tar yuzu-2195f10d152a52e01ccab0a6528f8758752d66a9.tar.gz yuzu-2195f10d152a52e01ccab0a6528f8758752d66a9.tar.bz2 yuzu-2195f10d152a52e01ccab0a6528f8758752d66a9.tar.lz yuzu-2195f10d152a52e01ccab0a6528f8758752d66a9.tar.xz yuzu-2195f10d152a52e01ccab0a6528f8758752d66a9.tar.zst yuzu-2195f10d152a52e01ccab0a6528f8758752d66a9.zip |
-rw-r--r-- | src/common/logging/backend.cpp | 3 | ||||
-rw-r--r-- | src/common/threadsafe_queue.h | 13 |
2 files changed, 9 insertions, 7 deletions
diff --git a/src/common/logging/backend.cpp b/src/common/logging/backend.cpp index 276e49f86..b369f199f 100644 --- a/src/common/logging/backend.cpp +++ b/src/common/logging/backend.cpp @@ -83,7 +83,8 @@ private: backend->Write(e); } }; - while (message_queue.PopWait(entry)) { + while (true) { + entry = message_queue.PopWait(); if (entry.final_entry) { break; } diff --git a/src/common/threadsafe_queue.h b/src/common/threadsafe_queue.h index 4fdcecca0..821e8536a 100644 --- a/src/common/threadsafe_queue.h +++ b/src/common/threadsafe_queue.h @@ -40,7 +40,7 @@ public: template <typename Arg> void Push(Arg&& t) { // create the element, add it to the queue - write_ptr->current = std::move(t); + write_ptr->current = std::forward<Arg>(t); // set the next pointer to a new element ptr // then advance the write pointer ElementPtr* new_ptr = new ElementPtr(); @@ -69,7 +69,6 @@ public: --size; ElementPtr* tmpptr = read_ptr; - read_ptr = tmpptr->next.load(std::memory_order_acquire); t = std::move(tmpptr->current); tmpptr->next.store(nullptr); @@ -77,12 +76,14 @@ public: return true; } - bool PopWait(T& t) { + T PopWait() { if (Empty()) { std::unique_lock<std::mutex> lock(cv_mutex); cv.wait(lock, [this]() { return !Empty(); }); } - return Pop(t); + T t; + Pop(t); + return t; } // not thread-safe @@ -148,8 +149,8 @@ public: return spsc_queue.Pop(t); } - bool PopWait(T& t) { - return spsc_queue.PopWait(t); + T PopWait() { + return spsc_queue.PopWait(); } // not thread-safe |