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 "versions.h"
#include <atomic>
#include <string>
#include <libconfig.h++>
using namespace libconfig;
@ -161,7 +162,7 @@ static int insock = -1;
static struct sockaddr_in outaddr;
static int serfd = -1;
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_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};

@ -48,6 +48,7 @@
#include <regex.h>
#include <pthread.h>
#include <atomic>
#include <string>
#include <map>
#include <libconfig.h++>
@ -117,7 +118,7 @@ static struct {
uint32_t adr;
struct sockaddr_in band_addr;
time_t last_time;
unsigned short G2_COUNTER;
std::atomic<unsigned short> G2_COUNTER;
unsigned char sequence;
} 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 volatile bool keep_running = true;
static std::atomic<bool> keep_running(true);
/* send packets to g2_link */
static struct sockaddr_in plug;
@ -906,7 +907,7 @@ static void runit()
for (j = 0; j < 2; j++)
sendto(srv_sock, (char *)end_of_audio, 29, 0, (struct sockaddr *)&toRptr[i].band_addr, sizeof(struct sockaddr_in));
toRptr[i].G2_COUNTER ++;
toRptr[i].G2_COUNTER++;
toRptr[i].streamid[0] = toRptr[i].streamid[1] = '\0';
toRptr[i].adr = 0;
@ -1029,7 +1030,7 @@ static void runit()
time(&toRptr[i].last_time);
/* bump the G2 counter */
toRptr[i].G2_COUNTER ++;
toRptr[i].G2_COUNTER++;
toRptr[i].sequence = readBuffer[16];
}
@ -1108,7 +1109,7 @@ static void runit()
sizeof(struct sockaddr_in));
/* bump G2 counter */
toRptr[i].G2_COUNTER ++;
toRptr[i].G2_COUNTER++;
/* send this audio packet to repeater */
memcpy(readBuffer,"DSTR", 4);
@ -1134,7 +1135,7 @@ static void runit()
time(&toRptr[i].last_time);
/* bump the G2 counter */
toRptr[i].G2_COUNTER ++;
toRptr[i].G2_COUNTER++;
toRptr[i].sequence = readBuffer[16];
@ -1483,7 +1484,7 @@ static void runit()
time(&toRptr[i].last_time);
/* bump the G2 counter */
toRptr[i].G2_COUNTER ++;
toRptr[i].G2_COUNTER++;
toRptr[i].sequence = readBuffer[16];
}
@ -2588,16 +2589,6 @@ static void *echotest(void *arg)
else if (dstar_buf[25] == 'C')
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);
rptr_buf[5] = (unsigned char)(toRptr[i].G2_COUNTER & 0xff);
rptr_buf[4] = (unsigned char)((toRptr[i].G2_COUNTER >> 8) & 0xff);

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

Loading…
Cancel
Save

Powered by TurnKey Linux.