Update net_tsqueue.h

pull/201/head
TheMaverickProgrammer 4 years ago committed by GitHub
parent b27c89cc59
commit 23de01a54b
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
  1. 16
      Videos/Networking/Parts1&2/net_tsqueue.h

@ -50,7 +50,7 @@
Author Author
~~~~~~ ~~~~~~
David Barr, aka javidx9, ©OneLoneCoder 2019, 2020 David Barr, aka javidx9, ©OneLoneCoder 2019, 2020
*/ */
@ -109,7 +109,6 @@ namespace olc
std::scoped_lock lock(muxQueue); std::scoped_lock lock(muxQueue);
deqQueue.emplace_back(std::move(item)); deqQueue.emplace_back(std::move(item));
std::unique_lock<std::mutex> ul(muxBlocking);
cvBlocking.notify_one(); cvBlocking.notify_one();
} }
@ -118,8 +117,7 @@ namespace olc
{ {
std::scoped_lock lock(muxQueue); std::scoped_lock lock(muxQueue);
deqQueue.emplace_front(std::move(item)); deqQueue.emplace_front(std::move(item));
std::unique_lock<std::mutex> ul(muxBlocking);
cvBlocking.notify_one(); cvBlocking.notify_one();
} }
@ -146,10 +144,11 @@ namespace olc
void wait() void wait()
{ {
while (empty()) std::unique_lock<std::mutex> ul(muxQueue);
while (deqQueue.empty())
{ {
std::unique_lock<std::mutex> ul(muxBlocking); cvBlocking.wait(ul);
cvBlocking.wait(ul);
} }
} }
@ -157,7 +156,6 @@ namespace olc
std::mutex muxQueue; std::mutex muxQueue;
std::deque<T> deqQueue; std::deque<T> deqQueue;
std::condition_variable cvBlocking; std::condition_variable cvBlocking;
std::mutex muxBlocking;
}; };
} }
} }

Loading…
Cancel
Save