Less data race in slsReceiver (#50)

* removed some data races

* non needed mutex

* removed extra include
This commit is contained in:
Erik Fröjdh 2019-08-21 12:02:06 +02:00 committed by Dhanya Thattil
parent b59d69325e
commit b4c207fc4e
6 changed files with 18 additions and 23 deletions

View File

@ -102,11 +102,10 @@ endif()
if(SLS_USE_SANITIZER)
target_compile_options(slsProjectOptions INTERFACE -fsanitize=address,undefined -fno-omit-frame-pointer)
#target_compile_options(slsProjectOptions INTERFACE -fsanitize=address,undefined)
target_link_libraries(slsProjectOptions INTERFACE -fsanitize=address,undefined)
# target_compile_options(slsProjectOptions INTERFACE -fsanitize=thread)
# target_link_libraries(slsProjectOptions INTERFACE -fsanitize=thread)
# target_compile_options(slsProjectOptions INTERFACE -fsanitize=address,undefined -fno-omit-frame-pointer)
# target_link_libraries(slsProjectOptions INTERFACE -fsanitize=address,undefined)
target_compile_options(slsProjectOptions INTERFACE -fsanitize=thread)
target_link_libraries(slsProjectOptions INTERFACE -fsanitize=thread)
endif()
#rapidjson

View File

@ -17,6 +17,7 @@ class File;
class DataStreamer;
#include <vector>
#include <atomic>
class DataProcessor : private virtual slsDetectorDefs, public ThreadObject {
@ -310,7 +311,7 @@ class DataProcessor : private virtual slsDetectorDefs, public ThreadObject {
static const std::string TypeName;
/** Object running status */
bool runningFlag;
std::atomic<bool> runningFlag;
/** GeneralData (Detector Data) object */
const GeneralData* generalData;

View File

@ -10,7 +10,7 @@
*/
#include <memory>
#include <atomic>
#include "ThreadObject.h"
class GeneralData;
@ -39,7 +39,7 @@ class Listener : private virtual slsDetectorDefs, public ThreadObject {
* @param depaden pointer to deactivated padding enable
* @param sm pointer to silent mode
*/
Listener(int ind, detectorType dtype, Fifo* f, runStatus* s,
Listener(int ind, detectorType dtype, Fifo* f, std::atomic<runStatus>* s,
uint32_t* portno, char* e, uint64_t* nf, uint32_t* dr,
int64_t* us, int64_t* as, uint32_t* fpf,
frameDiscardPolicy* fdp, bool* act, bool* depaden, bool* sm);
@ -151,7 +151,6 @@ class Listener : private virtual slsDetectorDefs, public ThreadObject {
void SetHardCodedPosition(uint16_t r, uint16_t c);
private:
/**
@ -201,7 +200,7 @@ class Listener : private virtual slsDetectorDefs, public ThreadObject {
static const std::string TypeName;
/** Object running status */
bool runningFlag;
std::atomic<bool> runningFlag;
/** GeneralData (Detector Data) object */
GeneralData* generalData;
@ -214,7 +213,7 @@ class Listener : private virtual slsDetectorDefs, public ThreadObject {
detectorType myDetectorType;
/** Receiver Status */
runStatus* status;
std::atomic<runStatus>* status;
/** UDP Socket - Detector to Receiver */
std::unique_ptr<genericSocket> udpSocket;
@ -264,10 +263,10 @@ class Listener : private virtual slsDetectorDefs, public ThreadObject {
// acquisition start
/** Aquisition Started flag */
bool acquisitionStartedFlag;
std::atomic<bool> acquisitionStartedFlag;
/** Measurement Started flag */
bool measurementStartedFlag;
std::atomic<bool> measurementStartedFlag;
/** Frame Number of First Frame of an entire Acquisition (including all scans) */
uint64_t firstAcquisitionIndex;
@ -278,10 +277,10 @@ class Listener : private virtual slsDetectorDefs, public ThreadObject {
// for acquisition summary
/** Number of complete Packets caught for each real time acquisition (eg. for each scan (start& stop of receiver)) */
volatile uint64_t numPacketsCaught;
std::atomic<uint64_t> numPacketsCaught;
/** Last Frame Index caught from udp network */
uint64_t lastCaughtFrameIndex;
std::atomic<uint64_t> lastCaughtFrameIndex;
// parameters to acquire image
@ -300,12 +299,11 @@ class Listener : private virtual slsDetectorDefs, public ThreadObject {
std::unique_ptr<char []> listeningPacket;
/** if the udp socket is connected */
bool udpSocketAlive;
std::atomic<bool> udpSocketAlive;
/** Semaphore to synchonize deleting udp socket */
sem_t semaphore_socket;
// for print progress during acqusition
/** number of packets for statistic */
uint32_t numPacketsStatistic;

View File

@ -21,6 +21,7 @@ class DataStreamer;
class Fifo;
class slsDetectorDefs;
#include <atomic>
#include <exception>
#include <memory>
#include <vector>
@ -910,7 +911,7 @@ class slsReceiverImplementation : private virtual slsDetectorDefs {
/** Maximum Number of Listening Threads/ UDP Ports */
const static int MAX_NUMBER_OF_LISTENING_THREADS = 2;
/** Receiver Status */
runStatus status;
std::atomic<runStatus> status;
/** Activated/Deactivated */
bool activated;
/** Deactivated padding enable */

View File

@ -20,7 +20,7 @@
const std::string Listener::TypeName = "Listener";
Listener::Listener(int ind, detectorType dtype, Fifo* f, runStatus* s,
Listener::Listener(int ind, detectorType dtype, Fifo* f, std::atomic<runStatus>* s,
uint32_t* portno, char* e, uint64_t* nf, uint32_t* dr,
int64_t* us, int64_t* as, uint32_t* fpf,
frameDiscardPolicy* fdp, bool* act, bool* depaden, bool* sm) :
@ -476,9 +476,6 @@ uint32_t Listener::ListenToAnImage(char* buf) {
}
//until last packet isHeaderEmpty to account for gotthard short frame, else never entering this loop)
while ( numpackets < pperFrame) {
//listen to new packet

View File

@ -44,7 +44,6 @@ class sockaddr_in;
#include <stdio.h>
#include "logger.h"
#define DEFAULT_PACKET_SIZE 1286
#define SOCKET_BUFFER_SIZE (100*1024*1024) //100 MB
#define DEFAULT_BACKLOG 5