Is this code correct?
I ask especially aboutCode:#define GRANULARITY 4 //Bytes
#define ALIGN __attribute__ ((aligned (GRANULARITY)))
typedef pthread_mutex_t ALIGN MUTEX;
typedef struct
{
MUTEX Mutex;
unsigned int MeasureActive;
unsigned int LastIndex;
unsigned int FirstIndex;
unsigned int ElementsNr;
unsigned long long int Overflow;
int64 RecordingInstant[MeasFIFO_SIZE];
unsigned int PacketIndex[MeasFIFO_SIZE];
int Value[MeasFIFO_SIZE];
} ALIGN Type_IntMeasFIFOComm;
typedef class c_IntWrParCAM_FIFOComm
{
public:
c_IntWrParCAM_FIFOComm() { pthread_mutex_init(&Mutex, NULL); }
~c_IntWrParCAM_FIFOComm() { pthread_mutex_destroy(&Mutex); }
MUTEX Mutex;
unsigned int LastIndex;
unsigned int FirstIndex;
unsigned int ElementsNr;
unsigned long long int Overflow;
unsigned int TargetIndex[WrFIFO_SIZE]; // DUMMY !!
unsigned int ParIndex[WrFIFO_SIZE];
int Value[WrFIFO_SIZE];
unsigned int ServerIndex[WrFIFO_SIZE];
int sock[WrFIFO_SIZE];
} ALIGN Type_IntWrParCAM_FIFOComm;
(1) the 4 usages of ALIGN (2 direct usages, 2 indirect via MUTEX)
(2) the use of the constructor destructor (those classes will have global object instances)
(3) the use of typedef class ..Type_IntWrParCAM_FIFOComm;
It is basically a variation of a structure just not to have to remember to call pthread_..init/destroy somewhere in the code (I often forget!!)