From be229cd2fa1d5b617d4a514ae9e1baed3761c36f Mon Sep 17 00:00:00 2001 From: Olivier Dion <olivier.dion@savoirfairelinux.com> Date: Thu, 29 Jul 2021 08:08:21 -0400 Subject: [PATCH] sip_utils: Nuke sip_utils::register_thread() Change-Id: I790b47971c6c202f7efeeb8c10db00ef430ca39c --- src/ice_transport.cpp | 8 -------- src/jamidht/channeled_transport.cpp | 1 - src/jamidht/jamiaccount.cpp | 3 --- src/sip/sdp.cpp | 4 ---- src/sip/sip_utils.cpp | 16 ---------------- src/sip/sip_utils.h | 6 ------ src/sip/sipaccount.cpp | 1 - src/sip/sipvoiplink.cpp | 2 -- 8 files changed, 41 deletions(-) diff --git a/src/ice_transport.cpp b/src/ice_transport.cpp index e7a7238f41..9906b028d5 100644 --- a/src/ice_transport.cpp +++ b/src/ice_transport.cpp @@ -296,7 +296,6 @@ add_turn_server(pj_pool_t& pool, pj_ice_strans_cfg& cfg, const TurnServerInfo& i IceTransport::Impl::Impl(const char* name, const IceTransportOptions& options) : pool_(nullptr, [](pj_pool_t* pool) { - sip_utils::register_thread(); pj_pool_release(pool); }) , on_initdone_cb_(options.onInitDone) @@ -318,7 +317,6 @@ IceTransport::Impl::Impl(const char* name, const IceTransportOptions& options) compCount_, initiatorSession_ ? "master" : "slave"); - sip_utils::register_thread(); if (options.upnpEnable) upnp_.reset(new upnp::Controller()); @@ -441,7 +439,6 @@ IceTransport::Impl::Impl(const char* name, const IceTransportOptions& options) // Must be created after any potential failure thread_ = std::thread([this] { - sip_utils::register_thread(); while (not threadTerminateFlags_) { // NOTE: handleEvents can return false in this case // but here we don't care if there is event or not. @@ -457,7 +454,6 @@ IceTransport::Impl::~Impl() { JAMI_DBG("[ice:%p] destroying %p", this, icest_); - sip_utils::register_thread(); threadTerminateFlags_ = true; iceCV_.notify_all(); @@ -1127,7 +1123,6 @@ IceTransport::isInitiator() const bool IceTransport::startIce(const Attribute& rem_attrs, std::vector<IceCandidate>&& rem_candidates) { - sip_utils::register_thread(); if (not isInitialized()) { JAMI_ERR("[ice:%p] not initialized transport", pimpl_.get()); @@ -1202,7 +1197,6 @@ IceTransport::startIce(const Attribute& rem_attrs, std::vector<IceCandidate>&& r bool IceTransport::startIce(const SDP& sdp) { - sip_utils::register_thread(); if (pimpl_->streamsCount_ != 1) { JAMI_ERR("Expected exactly one stream per SDP (found %u streams)", pimpl_->streamsCount_); @@ -1598,7 +1592,6 @@ IceTransport::send(unsigned compId, const unsigned char* buf, size_t len) { ASSERT_COMP_ID(compId, getComponentCount()); - sip_utils::register_thread(); auto remote = getRemoteAddress(compId); if (!remote) { @@ -1769,7 +1762,6 @@ IceTransportFactory::IceTransportFactory() }) , ice_cfg_() { - sip_utils::register_thread(); pj_caching_pool_init(cp_.get(), NULL, 0); diff --git a/src/jamidht/channeled_transport.cpp b/src/jamidht/channeled_transport.cpp index 33686919d9..fe2dd4065c 100644 --- a/src/jamidht/channeled_transport.cpp +++ b/src/jamidht/channeled_transport.cpp @@ -227,7 +227,6 @@ ChanneledSIPTransport::handleEvents() rxPending_.clear(); } - sip_utils::register_thread(); for (auto it = rx.begin(); it != rx.end(); ++it) { auto& pck = *it; pj_pool_reset(rdata_.tp_info.pool); diff --git a/src/jamidht/jamiaccount.cpp b/src/jamidht/jamiaccount.cpp index 81fc875051..169c032741 100644 --- a/src/jamidht/jamiaccount.cpp +++ b/src/jamidht/jamiaccount.cpp @@ -3293,7 +3293,6 @@ JamiAccount::sendTextMessage(const std::string& to, std::shared_ptr<std::set<DeviceId>> devices = std::make_shared<std::set<DeviceId>>(); std::unique_lock<std::mutex> lk(sipConnsMtx_); - sip_utils::register_thread(); for (auto it = sipConns_.begin(); it != sipConns_.end();) { auto& [key, value] = *it; @@ -4842,7 +4841,6 @@ JamiAccount::sendSIPMessage(SipConnection& conn, auto shared = w.lock(); if (!shared) return; - sip_utils::register_thread(); auto status = pjsip_endpt_send_request(shared->link_.getEndpoint(), tdata, -1, ctx, cb); if (status != PJ_SUCCESS) JAMI_ERR("Unable to send request: %s", sip_utils::sip_strerror(status).c_str()); @@ -4900,7 +4898,6 @@ JamiAccount::cacheSIPConnection(std::shared_ptr<ChannelSocket>&& socket, } // Convert to SIP transport - sip_utils::register_thread(); auto onShutdown = [w = weak(), peerId, key, socket]() { auto shared = w.lock(); if (!shared) diff --git a/src/sip/sdp.cpp b/src/sip/sdp.cpp index c11c62eb6f..51d7a505b0 100644 --- a/src/sip/sdp.cpp +++ b/src/sip/sdp.cpp @@ -59,7 +59,6 @@ static constexpr int POOL_INCREMENT_SIZE = POOL_INITIAL_SIZE; Sdp::Sdp(const std::string& id) : memPool_(nullptr, [](pj_pool_t* pool) { - sip_utils::register_thread(); pj_pool_release(pool); }) , publishedIpAddr_() @@ -67,7 +66,6 @@ Sdp::Sdp(const std::string& id) , telephoneEventPayload_(101) // same as asterisk , sessionName_("Call ID " + id) { - sip_utils::register_thread(); memPool_.reset(pj_pool_create(&Manager::instance().sipVoIPLink().getCachingPool()->factory, id.c_str(), POOL_INITIAL_SIZE, @@ -456,7 +454,6 @@ void Sdp::printSession(const pjmedia_sdp_session* session, const char* header, SdpDirection direction) { static constexpr size_t BUF_SZ = 4095; - sip_utils::register_thread(); std::unique_ptr<pj_pool_t, decltype(pj_pool_release)&> tmpPool_(pj_pool_create(&Manager::instance().sipVoIPLink().getCachingPool()->factory, "printSdp", @@ -674,7 +671,6 @@ Sdp::startNegotiation() std::string Sdp::getFilteredSdp(const pjmedia_sdp_session* session, unsigned media_keep, unsigned pt_keep) { - sip_utils::register_thread(); static constexpr size_t BUF_SZ = 4096; std::unique_ptr<pj_pool_t, decltype(pj_pool_release)&> tmpPool_(pj_pool_create(&Manager::instance().sipVoIPLink().getCachingPool()->factory, diff --git a/src/sip/sip_utils.cpp b/src/sip/sip_utils.cpp index 39a8e26b7c..5821bd346b 100644 --- a/src/sip/sip_utils.cpp +++ b/src/sip/sip_utils.cpp @@ -257,22 +257,6 @@ sip_strerror(pj_status_t code) return std::string {ret.ptr, ret.ptr + ret.slen}; } -void -register_thread() -{ - if (!pj_thread_is_registered()) { -#if __GNUC__ > 4 || (__GNUC__ == 4 && __GNUC_MINOR__ >= 8) || defined _MSC_VER - static thread_local pj_thread_desc desc; - static thread_local pj_thread_t* this_thread; -#else - static __thread pj_thread_desc desc; - static __thread pj_thread_t* this_thread; -#endif - pj_thread_register(NULL, desc, &this_thread); - JAMI_DBG("Registered thread %p (0x%X)", this_thread, pj_getpid()); - } -} - void sockaddr_to_host_port(pj_pool_t* pool, pjsip_host_port* host_port, const pj_sockaddr* addr) { diff --git a/src/sip/sip_utils.h b/src/sip/sip_utils.h index 0e8e59da30..31e58ca793 100644 --- a/src/sip/sip_utils.h +++ b/src/sip/sip_utils.h @@ -103,12 +103,6 @@ void logMessageHeaders(const pjsip_hdr* hdr_list); std::string sip_strerror(pj_status_t code); -/// \brief PJSIP requires to register all threads that access to its API. -/// -/// This function is safe to be called multiple time by same thread, -/// it will be registered only one time. -void register_thread(); - // Helper function that return a constant pj_str_t from an array of any types // that may be statically casted into char pointer. // Per convention, the input array is supposed to be null terminated. diff --git a/src/sip/sipaccount.cpp b/src/sip/sipaccount.cpp index dbe80b4dee..57d03bbb6b 100644 --- a/src/sip/sipaccount.cpp +++ b/src/sip/sipaccount.cpp @@ -2182,7 +2182,6 @@ SIPAccount::sendTextMessage(const std::string& to, return; } - sip_utils::register_thread(); auto toUri = getToUri(to); diff --git a/src/sip/sipvoiplink.cpp b/src/sip/sipvoiplink.cpp index 7c53483898..fc24618961 100644 --- a/src/sip/sipvoiplink.cpp +++ b/src/sip/sipvoiplink.cpp @@ -635,7 +635,6 @@ SIPVoIPLink::SIPVoIPLink() throw VoipLinkException(#ret " failed"); \ } while (0) - sip_utils::register_thread(); pj_caching_pool_init(&cp_, &pj_pool_factory_default_policy, 0); pool_.reset(pj_pool_create(&cp_.factory, PACKAGE, 64 * 1024, 4096, nullptr)); if (!pool_) @@ -748,7 +747,6 @@ SIPVoIPLink::SIPVoIPLink() #undef TRY sipThread_ = std::thread([this] { - sip_utils::register_thread(); while (running_) handleEvents(); }); -- GitLab