Browse Source

Made Processor keep an init token to prevent early threadpool join

Paul-Louis Ageneau 5 years ago
parent
commit
db00253c18
4 changed files with 7 additions and 6 deletions
  1. 1 1
      src/peerconnection.cpp
  2. 4 0
      src/processor.hpp
  3. 1 4
      src/threadpool.cpp
  4. 1 1
      src/websocket.cpp

+ 1 - 1
src/peerconnection.cpp

@@ -449,7 +449,7 @@ void PeerConnection::closeTransports() {
 	auto sctp = std::atomic_exchange(&mSctpTransport, decltype(mSctpTransport)(nullptr));
 	auto dtls = std::atomic_exchange(&mDtlsTransport, decltype(mDtlsTransport)(nullptr));
 	auto ice = std::atomic_exchange(&mIceTransport, decltype(mIceTransport)(nullptr));
-	ThreadPool::Instance().enqueue([sctp, dtls, ice, token = mInitToken]() mutable {
+	ThreadPool::Instance().enqueue([sctp, dtls, ice]() mutable {
 		if (sctp)
 			sctp->stop();
 		if (dtls)

+ 4 - 0
src/processor.hpp

@@ -20,6 +20,7 @@
 #define RTC_PROCESSOR_H
 
 #include "include.hpp"
+#include "init.hpp"
 #include "threadpool.hpp"
 
 #include <condition_variable>
@@ -49,6 +50,9 @@ public:
 protected:
 	void schedule();
 
+	// Keep an init token
+	const init_token mInitToken = Init::Token();
+
 	std::queue<std::function<void()>> mTasks;
 	bool mPending = false; // true iff a task is pending in the thread pool
 

+ 1 - 4
src/threadpool.cpp

@@ -45,10 +45,7 @@ void ThreadPool::join() {
 	mCondition.notify_all();
 
 	for (auto &w : mWorkers)
-		if (w.get_id() == std::this_thread::get_id())
-			w.detach(); // detach ourselves
-		else
-			w.join(); // join others
+		w.join();
 
 	mWorkers.clear();
 }

+ 1 - 1
src/websocket.cpp

@@ -302,7 +302,7 @@ void WebSocket::closeTransports() {
 	auto ws = std::atomic_exchange(&mWsTransport, decltype(mWsTransport)(nullptr));
 	auto tls = std::atomic_exchange(&mTlsTransport, decltype(mTlsTransport)(nullptr));
 	auto tcp = std::atomic_exchange(&mTcpTransport, decltype(mTcpTransport)(nullptr));
-	ThreadPool::Instance().enqueue([ws, tls, tcp, token = Init::Token()]() mutable {
+	ThreadPool::Instance().enqueue([ws, tls, tcp]() mutable {
 		if (ws)
 			ws->stop();
 		if (tls)