From 17edc30141a5587074c56d3d65a5ae6af58db8b0 Mon Sep 17 00:00:00 2001 From: Tom Early Date: Sat, 20 Apr 2024 16:25:57 -0700 Subject: [PATCH] no concurrent audio threads --- QnetDVAP.cpp | 25 +------------------------ QnetDVAP.h | 2 -- QnetGateway.cpp | 49 +++---------------------------------------------- QnetGateway.h | 2 -- QnetLink.cpp | 35 ++--------------------------------- QnetLink.h | 3 --- 6 files changed, 6 insertions(+), 110 deletions(-) diff --git a/QnetDVAP.cpp b/QnetDVAP.cpp index 6ed7e3d..708fd1b 100644 --- a/QnetDVAP.cpp +++ b/QnetDVAP.cpp @@ -841,14 +841,7 @@ void CQnetDVAP::ReadDVAPThread() if (MODULE_ACKNOWLEDGE && !busy20000) { memcpy(dvap_ack_arg.mycall, mycall, 8); - try - { - m_fqueue.emplace(std::async(std::launch::async, &CQnetDVAP::RptrAckThread, this, &dvap_ack_arg)); - } - catch (const std::exception &e) - { - printf("Failed to start RptrAckThread(). Exception: %s\n", e.what()); - } + RptrAckThread(&dvap_ack_arg); } } } @@ -957,22 +950,6 @@ void CQnetDVAP::Run() ackpoint.start(); } ReadFromGateway(); - - if (! m_fqueue.empty()) - { - if (m_fqueue.front().valid()) - { - if (std::future_status::ready == m_fqueue.front().wait_for(std::chrono::seconds(0))) - { - m_fqueue.front().get(); - m_fqueue.pop(); - } - } - else - { - m_fqueue.pop(); - } - } } } diff --git a/QnetDVAP.h b/QnetDVAP.h index ddf58da..17c39e5 100644 --- a/QnetDVAP.h +++ b/QnetDVAP.h @@ -19,7 +19,6 @@ */ #include -#include #include "UnixDgramSocket.h" #include "Base.h" @@ -53,7 +52,6 @@ private: CRandom Random; // data - std::queue> m_fqueue; std::future m_readThread; // unix sockets diff --git a/QnetGateway.cpp b/QnetGateway.cpp index f5ec57c..6801304 100644 --- a/QnetGateway.cpp +++ b/QnetGateway.cpp @@ -612,17 +612,7 @@ void CQnetGateway::ProcessTimeouts() // printf("Closed echotest audio file:[%s]\n", recd[i].file); /* START: echotest thread setup */ - try - { - m_fqueue.emplace(std::async(std::launch::async, &CQnetGateway::PlayFileThread, this, std::ref(recd[i]))); - } - catch (const std::exception &e) - { - printf("Failed to start echotest thread. Exception: %s\n", e.what()); - // when the echotest thread runs, it deletes the file, - // Because the echotest thread did NOT start, we delete the file here - unlink(recd[i].file); - } + PlayFileThread(recd[i]); /* END: echotest thread setup */ } } @@ -1678,14 +1668,7 @@ void CQnetGateway::ProcessModem(const ssize_t recvlen, SDSVT &dsvt) band_txt[i].last_time = 0; band_txt[i].streamID = 0U; // prevent vm timeout snprintf(vm[i].message, 21, "VOICEMAIL ON MOD %c ", 'A'+i); - try - { - m_fqueue.emplace(std::async(std::launch::async, &CQnetGateway::PlayFileThread, this, std::ref(vm[i]))); - } - catch (const std::exception &e) - { - printf("Failed to start voicemail playback. Exception: %s\n", e.what()); - } + PlayFileThread(vm[i]); } else printf("No voicemail to recall or still recording\n"); @@ -1970,17 +1953,7 @@ void CQnetGateway::ProcessModem(const ssize_t recvlen, SDSVT &dsvt) // printf("Closed echotest audio file:[%s]\n", recd[i].file); /* we are in echotest mode, so play it back */ - try - { - m_fqueue.emplace(std::async(std::launch::async, &CQnetGateway::PlayFileThread, this, std::ref(recd[i]))); - } - catch (const std::exception &e) - { - printf("failed to start PlayFileThread. Exception: %s\n", e.what()); - // When the echotest thread runs, it deletes the file, - // Because the echotest thread did NOT start, we delete the file here - unlink(recd[i].file); - } + PlayFileThread(recd[i]); } break; } @@ -2076,22 +2049,6 @@ void CQnetGateway::Run() while (keep_running) { - if (! m_fqueue.empty()) - { - if (m_fqueue.front().valid()) - { - if (std::future_status::ready == m_fqueue.front().wait_for(std::chrono::seconds(0))) - { - m_fqueue.front().get(); - m_fqueue.pop(); - } - } - else - { - m_fqueue.pop(); - } - } - ProcessTimeouts(); // wait 20 ms max diff --git a/QnetGateway.h b/QnetGateway.h index 9962877..a2f8d99 100644 --- a/QnetGateway.h +++ b/QnetGateway.h @@ -19,7 +19,6 @@ #include #include #include -#include #include "IRCDDB.h" #include "QnetTypeDefs.h" @@ -101,7 +100,6 @@ public: void Close(); private: - std::queue> m_fqueue; // link type int link_family[3] = { AF_UNSPEC, AF_UNSPEC, AF_UNSPEC }; // network type diff --git a/QnetLink.cpp b/QnetLink.cpp index f4371a9..b12a935 100644 --- a/QnetLink.cpp +++ b/QnetLink.cpp @@ -348,14 +348,7 @@ void CQnetLink::rptr_ack(int i) { memcpy(mod_and_RADIO_ID[i] + 1, "NOT LINKED", 10); } - try - { - m_fqueue.emplace(std::async(std::launch::async, &CQnetLink::RptrAckThread, this, mod_and_RADIO_ID[i])); - } - catch (const std::exception &e) - { - printf("Failed to start RptrAckThread(). Exception: %s\n", e.what()); - } + RptrAckThread(mod_and_RADIO_ID[i]); return; } @@ -2743,23 +2736,6 @@ void CQnetLink::Run() while (keep_running) { - if (! m_fqueue.empty()) - { - auto &fut = m_fqueue.front(); - if (fut.valid()) - { - if (std::future_status::ready == fut.wait_for(std::chrono::seconds(0))) - { - fut.get(); - m_fqueue.pop(); - } - } - else - { - m_fqueue.pop(); - } - } - static bool loadG[3] = { false, false, false }; time(&tnow); if (keep_running && (tnow - heartbeat) > 0) @@ -3485,14 +3461,7 @@ void CQnetLink::PlayAudioNotifyThread(char *msg) memcpy(edata.header.hdr.sfx, "RPTR", 4); calcPFCS(edata.header.title, 56); - try - { - m_fqueue.emplace(std::async(std::launch::async, &CQnetLink::AudioNotifyThread, this, std::ref(edata))); - } - catch (const std::exception &e) - { - printf ("Failed to start AudioNotifyThread(). Exception: %s\n", e.what()); - } + AudioNotifyThread(edata); return; } diff --git a/QnetLink.h b/QnetLink.h index 72d3dc2..e2191bd 100644 --- a/QnetLink.h +++ b/QnetLink.h @@ -23,7 +23,6 @@ #include #include #include -#include #include #include @@ -124,8 +123,6 @@ private: int rf_inactivity_timer[3]; const unsigned char REF_ACK[3] = { 3, 96, 0 }; - std::queue> m_fqueue; - // the Key in this inbound_list map is the unique IP address of the remote std::map inbound_list;