a .get() for every std::future

dev
Tom Early 2 years ago
parent 6b77a0c029
commit d73c59ba9c

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

@ -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();

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

@ -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

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

@ -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)
{

@ -23,6 +23,8 @@
#include <map>
#include <vector>
#include <set>
#include <queue>
#include <future>
#include <netinet/in.h>
#include "QnetTypeDefs.h"
@ -122,6 +124,8 @@ private:
int rf_inactivity_timer[3];
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
std::map<std::string, SINBOUND *> inbound_list;

Loading…
Cancel
Save

Powered by TurnKey Linux.