a .get() for every std::future

dev
Tom Early 2 years ago
parent 6b77a0c029
commit d73c59ba9c

@ -26,8 +26,8 @@ CQnetConfigure::CQnetConfigure()
CQnetConfigure::~CQnetConfigure() CQnetConfigure::~CQnetConfigure()
{ {
defaults.empty(); defaults.clear();
cfg.empty(); cfg.clear();
} }
char *CQnetConfigure::Trim(char *s) char *CQnetConfigure::Trim(char *s)

@ -49,7 +49,7 @@
#include "DStarDecode.h" #include "DStarDecode.h"
#include "QnetDVAP.h" #include "QnetDVAP.h"
#define DVAP_VERSION "QnetDVAP-20307" #define DVAP_VERSION "QnetDVAP-40411"
#define CALL_SIZE 8 #define CALL_SIZE 8
#define IP_SIZE 15 #define IP_SIZE 15
@ -846,7 +846,7 @@ void CQnetDVAP::ReadDVAPThread()
memcpy(dvap_ack_arg.mycall, mycall, 8); memcpy(dvap_ack_arg.mycall, mycall, 8);
try 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) catch (const std::exception &e)
{ {
@ -955,6 +955,22 @@ void CQnetDVAP::Run()
ackpoint.start(); ackpoint.start();
} }
ReadFromGateway(); 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(); readthread.get();

@ -18,6 +18,9 @@
* Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA. * Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
*/ */
#include <future>
#include <queue>
#include "KRBase.h" #include "KRBase.h"
using SDVAP_ACK_ARG = struct davp_ack_arg_tag using SDVAP_ACK_ARG = struct davp_ack_arg_tag
@ -46,6 +49,7 @@ private:
CRandom Random; CRandom Random;
// data // data
std::queue<std::future<void>> m_fqueue;
int assigned_module; int assigned_module;
// unix sockets // unix sockets

@ -50,7 +50,7 @@
#include "QnetGateway.h" #include "QnetGateway.h"
#include "Utilities.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 int CQnetGateway::FindIndex(const int i) const
{ {
@ -614,7 +614,7 @@ void CQnetGateway::ProcessTimeouts()
/* START: echotest thread setup */ /* START: echotest thread setup */
try 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) 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) if (smrtgrp.size() < 8)
{ {
// something bad happened // something bad happened
smrtgrp.empty(); smrtgrp.clear();
return false; return false;
} }
return true; 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); snprintf(vm[i].message, 21, "VOICEMAIL ON MOD %c ", 'A'+i);
try 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) 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 */ /* we are in echotest mode, so play it back */
try 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) catch (const std::exception &e)
{ {
@ -2076,6 +2076,22 @@ void CQnetGateway::Process()
while (IsRunning()) 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(); ProcessTimeouts();
// wait 20 ms max // wait 20 ms max

@ -18,6 +18,8 @@
#include <set> #include <set>
#include <regex> #include <regex>
#include <future>
#include <queue>
#include "IRCDDB.h" #include "IRCDDB.h"
#include "QnetTypeDefs.h" #include "QnetTypeDefs.h"
@ -100,6 +102,7 @@ public:
bool Init(char *cfgfile); bool Init(char *cfgfile);
private: private:
std::queue<std::future<void>> m_fqueue;
// link type // link type
int link_family[3] = { AF_UNSPEC, AF_UNSPEC, AF_UNSPEC }; int link_family[3] = { AF_UNSPEC, AF_UNSPEC, AF_UNSPEC };
// network type // network type

@ -54,7 +54,7 @@
#include "QnetLink.h" #include "QnetLink.h"
#include "Utilities.h" #include "Utilities.h"
#define LINK_VERSION "QnetLink-20520" #define LINK_VERSION "QnetLink-40411"
CQnetLink::CQnetLink() CQnetLink::CQnetLink()
{ {
@ -350,7 +350,7 @@ void CQnetLink::rptr_ack(int i)
} }
try 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) catch (const std::exception &e)
{ {
@ -2744,6 +2744,23 @@ void CQnetLink::Process()
while (keep_running) 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 }; static bool loadG[3] = { false, false, false };
time(&tnow); time(&tnow);
if (keep_running && (tnow - heartbeat) > 0) if (keep_running && (tnow - heartbeat) > 0)
@ -3471,7 +3488,7 @@ void CQnetLink::PlayAudioNotifyThread(char *msg)
try 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) catch (const std::exception &e)
{ {

@ -23,6 +23,8 @@
#include <map> #include <map>
#include <vector> #include <vector>
#include <set> #include <set>
#include <queue>
#include <future>
#include <netinet/in.h> #include <netinet/in.h>
#include "QnetTypeDefs.h" #include "QnetTypeDefs.h"
@ -122,6 +124,8 @@ private:
int rf_inactivity_timer[3]; int rf_inactivity_timer[3];
const unsigned char REF_ACK[3] = { 3, 96, 0 }; const unsigned char REF_ACK[3] = { 3, 96, 0 };
std::queue<std::future<void>> m_fqueue;
// the Key in this inbound_list map is the unique IP address of the remote // the Key in this inbound_list map is the unique IP address of the remote
std::map<std::string, SINBOUND *> inbound_list; std::map<std::string, SINBOUND *> inbound_list;

Loading…
Cancel
Save

Powered by TurnKey Linux.