mirror of
https://github.com/Lime3DS/Lime3DS.git
synced 2024-11-24 02:29:20 +01:00
Adressed review comments
This commit is contained in:
parent
7efe60ed23
commit
ad8b9c0429
@ -81,7 +81,8 @@ private:
|
|||||||
backend->Write(e);
|
backend->Write(e);
|
||||||
}
|
}
|
||||||
};
|
};
|
||||||
while (message_queue.PopWait(entry)) {
|
while (true) {
|
||||||
|
entry = message_queue.PopWait();
|
||||||
if (entry.final_entry) {
|
if (entry.final_entry) {
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
|
@ -42,7 +42,7 @@ public:
|
|||||||
template <typename Arg>
|
template <typename Arg>
|
||||||
void Push(Arg&& t) {
|
void Push(Arg&& t) {
|
||||||
// create the element, add it to the queue
|
// 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
|
// set the next pointer to a new element ptr
|
||||||
// then advance the write pointer
|
// then advance the write pointer
|
||||||
ElementPtr* new_ptr = new ElementPtr();
|
ElementPtr* new_ptr = new ElementPtr();
|
||||||
@ -68,11 +68,10 @@ public:
|
|||||||
if (Empty())
|
if (Empty())
|
||||||
return false;
|
return false;
|
||||||
|
|
||||||
ElementPtr* tmpptr = read_ptr;
|
|
||||||
|
|
||||||
if (NeedSize)
|
if (NeedSize)
|
||||||
size--;
|
size--;
|
||||||
|
|
||||||
|
ElementPtr* tmpptr = read_ptr;
|
||||||
read_ptr = tmpptr->next.load(std::memory_order_acquire);
|
read_ptr = tmpptr->next.load(std::memory_order_acquire);
|
||||||
t = std::move(tmpptr->current);
|
t = std::move(tmpptr->current);
|
||||||
tmpptr->next.store(nullptr);
|
tmpptr->next.store(nullptr);
|
||||||
@ -80,12 +79,14 @@ public:
|
|||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
|
|
||||||
bool PopWait(T& t) {
|
T PopWait() {
|
||||||
if (Empty()) {
|
if (Empty()) {
|
||||||
std::unique_lock<std::mutex> lock(cv_mutex);
|
std::unique_lock<std::mutex> lock(cv_mutex);
|
||||||
cv.wait(lock, [this]() { return !Empty(); });
|
cv.wait(lock, [this]() { return !Empty(); });
|
||||||
}
|
}
|
||||||
return Pop(t);
|
T t;
|
||||||
|
Pop(t);
|
||||||
|
return t;
|
||||||
}
|
}
|
||||||
|
|
||||||
// not thread-safe
|
// not thread-safe
|
||||||
@ -151,8 +152,8 @@ public:
|
|||||||
return spsc_queue.Pop(t);
|
return spsc_queue.Pop(t);
|
||||||
}
|
}
|
||||||
|
|
||||||
bool PopWait(T& t) {
|
T PopWait() {
|
||||||
return spsc_queue.PopWait(t);
|
return spsc_queue.PopWait();
|
||||||
}
|
}
|
||||||
|
|
||||||
// not thread-safe
|
// not thread-safe
|
||||||
|
@ -106,10 +106,7 @@ void RPCServer::HandleRequestsLoop() {
|
|||||||
|
|
||||||
LOG_INFO(RPC_Server, "Request handler started.");
|
LOG_INFO(RPC_Server, "Request handler started.");
|
||||||
|
|
||||||
while (request_queue.PopWait(request_packet)) {
|
while ((request_packet = request_queue.PopWait())) {
|
||||||
if (!request_packet) {
|
|
||||||
break;
|
|
||||||
}
|
|
||||||
HandleSingleRequest(std::move(request_packet));
|
HandleSingleRequest(std::move(request_packet));
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
Loading…
Reference in New Issue
Block a user