std::atomic for all keep_running and G2_COUNTER in g2_ircddb

pull/1/head
Tom Early 9 years ago
parent 0c0d038d14
commit ed8ebf26a0

@ -41,6 +41,7 @@
#include <pthread.h> #include <pthread.h>
#include "versions.h" #include "versions.h"
#include <atomic>
#include <string> #include <string>
#include <libconfig.h++> #include <libconfig.h++>
using namespace libconfig; using namespace libconfig;
@ -161,7 +162,7 @@ static int insock = -1;
static struct sockaddr_in outaddr; static struct sockaddr_in outaddr;
static int serfd = -1; static int serfd = -1;
static bool busy20000 = false; static bool busy20000 = false;
static bool keep_running = true; static std::atomic<bool> keep_running(true);
static unsigned char DVP_RQST_NAME[] = {0x04, 0x20, 0x01, 0x00}; static unsigned char DVP_RQST_NAME[] = {0x04, 0x20, 0x01, 0x00};
static unsigned char DVP_REPL_NAME[] = {0x10, 0x00, 0x01, 0x00, 'D', 'V', 'A', 'P', ' ', 'D', 'o', 'n', 'g', 'l', 'e', 0x00}; static unsigned char DVP_REPL_NAME[] = {0x10, 0x00, 0x01, 0x00, 'D', 'V', 'A', 'P', ' ', 'D', 'o', 'n', 'g', 'l', 'e', 0x00};
static unsigned char DVP_RQST_SER[] = {0x04, 0x20, 0x02, 0x00}; static unsigned char DVP_RQST_SER[] = {0x04, 0x20, 0x02, 0x00};

@ -48,6 +48,7 @@
#include <regex.h> #include <regex.h>
#include <pthread.h> #include <pthread.h>
#include <atomic>
#include <string> #include <string>
#include <map> #include <map>
#include <libconfig.h++> #include <libconfig.h++>
@ -117,7 +118,7 @@ static struct {
uint32_t adr; uint32_t adr;
struct sockaddr_in band_addr; struct sockaddr_in band_addr;
time_t last_time; time_t last_time;
unsigned short G2_COUNTER; std::atomic<unsigned short> G2_COUNTER;
unsigned char sequence; unsigned char sequence;
} toRptr[3]; /* 0=A, 1=B, 2=C */ } toRptr[3]; /* 0=A, 1=B, 2=C */
@ -128,7 +129,7 @@ static struct sockaddr_in fromRptr;
static unsigned char end_of_audio[29]; static unsigned char end_of_audio[29];
static volatile bool keep_running = true; static std::atomic<bool> keep_running(true);
/* send packets to g2_link */ /* send packets to g2_link */
static struct sockaddr_in plug; static struct sockaddr_in plug;
@ -2588,16 +2589,6 @@ static void *echotest(void *arg)
else if (dstar_buf[25] == 'C') else if (dstar_buf[25] == 'C')
i = 2; i = 2;
/***
WARNING: G2_COUNTER is accessed by both threads.
It should be protected with a MUTEX,
but since this version is NOT for RP2C, but for home-brew
it does not really matter.
Anyway, accessing G2_COUNTER and adding 1 to it,
should be an atomic operation.
***/
memcpy(rptr_buf, "DSTR", 4); memcpy(rptr_buf, "DSTR", 4);
rptr_buf[5] = (unsigned char)(toRptr[i].G2_COUNTER & 0xff); rptr_buf[5] = (unsigned char)(toRptr[i].G2_COUNTER & 0xff);
rptr_buf[4] = (unsigned char)((toRptr[i].G2_COUNTER >> 8) & 0xff); rptr_buf[4] = (unsigned char)((toRptr[i].G2_COUNTER >> 8) & 0xff);

@ -45,7 +45,7 @@
#include <netdb.h> #include <netdb.h>
#include <pthread.h> #include <pthread.h>
#include <atomic>
/* Required for Binary search trees using C++ STL */ /* Required for Binary search trees using C++ STL */
#include <string> #include <string>
#include <set> #include <set>
@ -198,7 +198,7 @@ static struct sockaddr_in fromRptr;
static fd_set fdset; static fd_set fdset;
static struct timeval tv; static struct timeval tv;
static bool keep_running = true; static std::atomic<bool> keep_running(true);
/* Used to validate incoming donglers */ /* Used to validate incoming donglers */
static regex_t preg; static regex_t preg;

Loading…
Cancel
Save

Powered by TurnKey Linux.