From d73c59ba9c592ce56659a3644991624f6efbcc07 Mon Sep 17 00:00:00 2001 From: Tom Early Date: Thu, 11 Apr 2024 12:36:23 -0700 Subject: [PATCH] a .get() for every std::future --- QnetConfigure.cpp | 4 ++-- QnetDVAP.cpp | 20 ++++++++++++++++++-- QnetDVAP.h | 4 ++++ QnetGateway.cpp | 26 +++++++++++++++++++++----- QnetGateway.h | 3 +++ QnetLink.cpp | 23 ++++++++++++++++++++--- QnetLink.h | 4 ++++ 7 files changed, 72 insertions(+), 12 deletions(-) diff --git a/QnetConfigure.cpp b/QnetConfigure.cpp index 43b4dad..7c7afad 100644 --- a/QnetConfigure.cpp +++ b/QnetConfigure.cpp @@ -26,8 +26,8 @@ CQnetConfigure::CQnetConfigure() CQnetConfigure::~CQnetConfigure() { - defaults.empty(); - cfg.empty(); + defaults.clear(); + cfg.clear(); } char *CQnetConfigure::Trim(char *s) diff --git a/QnetDVAP.cpp b/QnetDVAP.cpp index 46aa834..8db53a7 100644 --- a/QnetDVAP.cpp +++ b/QnetDVAP.cpp @@ -49,7 +49,7 @@ #include "DStarDecode.h" #include "QnetDVAP.h" -#define DVAP_VERSION "QnetDVAP-20307" +#define DVAP_VERSION "QnetDVAP-40411" #define CALL_SIZE 8 #define IP_SIZE 15 @@ -846,7 +846,7 @@ void CQnetDVAP::ReadDVAPThread() memcpy(dvap_ack_arg.mycall, mycall, 8); try { - std::async(std::launch::async, &CQnetDVAP::RptrAckThread, this, &dvap_ack_arg); + m_fqueue.emplace(std::async(std::launch::async, &CQnetDVAP::RptrAckThread, this, &dvap_ack_arg)); } catch (const std::exception &e) { @@ -955,6 +955,22 @@ 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(); + } + } } readthread.get(); diff --git a/QnetDVAP.h b/QnetDVAP.h index 00cfcf8..4002430 100644 --- a/QnetDVAP.h +++ b/QnetDVAP.h @@ -18,6 +18,9 @@ * Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA. */ +#include +#include + #include "KRBase.h" using SDVAP_ACK_ARG = struct davp_ack_arg_tag @@ -46,6 +49,7 @@ private: CRandom Random; // data + std::queue> m_fqueue; int assigned_module; // unix sockets diff --git a/QnetGateway.cpp b/QnetGateway.cpp index 01da996..58d93eb 100644 --- a/QnetGateway.cpp +++ b/QnetGateway.cpp @@ -50,7 +50,7 @@ #include "QnetGateway.h" #include "Utilities.h" -const std::string GW_VERSION("QnetGateway-40302"); +const std::string GW_VERSION("QnetGateway-40411"); int CQnetGateway::FindIndex(const int i) const { @@ -614,7 +614,7 @@ void CQnetGateway::ProcessTimeouts() /* START: echotest thread setup */ try { - std::async(std::launch::async, &CQnetGateway::PlayFileThread, this, std::ref(recd[i])); + m_fqueue.emplace(std::async(std::launch::async, &CQnetGateway::PlayFileThread, this, std::ref(recd[i]))); } catch (const std::exception &e) { @@ -723,7 +723,7 @@ bool CQnetGateway::ProcessG2Msg(const unsigned char *data, const int mod, std::s if (smrtgrp.size() < 8) { // something bad happened - smrtgrp.empty(); + smrtgrp.clear(); return false; } return true; @@ -1680,7 +1680,7 @@ void CQnetGateway::ProcessModem(const ssize_t recvlen, SDSVT &dsvt) snprintf(vm[i].message, 21, "VOICEMAIL ON MOD %c ", 'A'+i); try { - std::async(std::launch::async, &CQnetGateway::PlayFileThread, this, std::ref(vm[i])); + m_fqueue.emplace(std::async(std::launch::async, &CQnetGateway::PlayFileThread, this, std::ref(vm[i]))); } catch (const std::exception &e) { @@ -1972,7 +1972,7 @@ void CQnetGateway::ProcessModem(const ssize_t recvlen, SDSVT &dsvt) /* we are in echotest mode, so play it back */ try { - std::async(std::launch::async, &CQnetGateway::PlayFileThread, this, std::ref(recd[i])); + m_fqueue.emplace(std::async(std::launch::async, &CQnetGateway::PlayFileThread, this, std::ref(recd[i]))); } catch (const std::exception &e) { @@ -2076,6 +2076,22 @@ void CQnetGateway::Process() while (IsRunning()) { + 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 e4b10e7..d1df62e 100644 --- a/QnetGateway.h +++ b/QnetGateway.h @@ -18,6 +18,8 @@ #include #include +#include +#include #include "IRCDDB.h" #include "QnetTypeDefs.h" @@ -100,6 +102,7 @@ public: bool Init(char *cfgfile); 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 680f59c..ecf1a5a 100644 --- a/QnetLink.cpp +++ b/QnetLink.cpp @@ -54,7 +54,7 @@ #include "QnetLink.h" #include "Utilities.h" -#define LINK_VERSION "QnetLink-20520" +#define LINK_VERSION "QnetLink-40411" CQnetLink::CQnetLink() { @@ -350,7 +350,7 @@ void CQnetLink::rptr_ack(int i) } try { - std::async(std::launch::async, &CQnetLink::RptrAckThread, this, mod_and_RADIO_ID[i]); + m_fqueue.emplace(std::async(std::launch::async, &CQnetLink::RptrAckThread, this, mod_and_RADIO_ID[i])); } catch (const std::exception &e) { @@ -2744,6 +2744,23 @@ void CQnetLink::Process() 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) @@ -3471,7 +3488,7 @@ void CQnetLink::PlayAudioNotifyThread(char *msg) try { - std::async(std::launch::async, &CQnetLink::AudioNotifyThread, this, std::ref(edata)); + m_fqueue.emplace(std::async(std::launch::async, &CQnetLink::AudioNotifyThread, this, std::ref(edata))); } catch (const std::exception &e) { diff --git a/QnetLink.h b/QnetLink.h index cc346fd..c105e62 100644 --- a/QnetLink.h +++ b/QnetLink.h @@ -23,6 +23,8 @@ #include #include #include +#include +#include #include #include "QnetTypeDefs.h" @@ -122,6 +124,8 @@ 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;