summaryrefslogtreecommitdiff
path: root/src
diff options
context:
space:
mode:
authorGravatar B3n302018-10-08 23:28:54 +0200
committerGravatar fearlessTobi2019-02-15 22:14:54 +0100
commit2195f10d152a52e01ccab0a6528f8758752d66a9 (patch)
tree6bf2fb03d0df8224a44259eed4a773bc67fe4b45 /src
parentthreadsafe_queue: Add WaitIfEmpty and use it in logging (diff)
downloadyuzu-2195f10d152a52e01ccab0a6528f8758752d66a9.tar.gz
yuzu-2195f10d152a52e01ccab0a6528f8758752d66a9.tar.xz
yuzu-2195f10d152a52e01ccab0a6528f8758752d66a9.zip
Adressed review comments
Diffstat (limited to 'src')
-rw-r--r--src/common/logging/backend.cpp3
-rw-r--r--src/common/threadsafe_queue.h13
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:
83 backend->Write(e); 83 backend->Write(e);
84 } 84 }
85 }; 85 };
86 while (message_queue.PopWait(entry)) { 86 while (true) {
87 entry = message_queue.PopWait();
87 if (entry.final_entry) { 88 if (entry.final_entry) {
88 break; 89 break;
89 } 90 }
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:
40 template <typename Arg> 40 template <typename Arg>
41 void Push(Arg&& t) { 41 void Push(Arg&& t) {
42 // create the element, add it to the queue 42 // create the element, add it to the queue
43 write_ptr->current = std::move(t); 43 write_ptr->current = std::forward<Arg>(t);
44 // set the next pointer to a new element ptr 44 // set the next pointer to a new element ptr
45 // then advance the write pointer 45 // then advance the write pointer
46 ElementPtr* new_ptr = new ElementPtr(); 46 ElementPtr* new_ptr = new ElementPtr();
@@ -69,7 +69,6 @@ public:
69 --size; 69 --size;
70 70
71 ElementPtr* tmpptr = read_ptr; 71 ElementPtr* tmpptr = read_ptr;
72
73 read_ptr = tmpptr->next.load(std::memory_order_acquire); 72 read_ptr = tmpptr->next.load(std::memory_order_acquire);
74 t = std::move(tmpptr->current); 73 t = std::move(tmpptr->current);
75 tmpptr->next.store(nullptr); 74 tmpptr->next.store(nullptr);
@@ -77,12 +76,14 @@ public:
77 return true; 76 return true;
78 } 77 }
79 78
80 bool PopWait(T& t) { 79 T PopWait() {
81 if (Empty()) { 80 if (Empty()) {
82 std::unique_lock<std::mutex> lock(cv_mutex); 81 std::unique_lock<std::mutex> lock(cv_mutex);
83 cv.wait(lock, [this]() { return !Empty(); }); 82 cv.wait(lock, [this]() { return !Empty(); });
84 } 83 }
85 return Pop(t); 84 T t;
85 Pop(t);
86 return t;
86 } 87 }
87 88
88 // not thread-safe 89 // not thread-safe
@@ -148,8 +149,8 @@ public:
148 return spsc_queue.Pop(t); 149 return spsc_queue.Pop(t);
149 } 150 }
150 151
151 bool PopWait(T& t) { 152 T PopWait() {
152 return spsc_queue.PopWait(t); 153 return spsc_queue.PopWait();
153 } 154 }
154 155
155 // not thread-safe 156 // not thread-safe