Merge branch 'master' of https://gitea.auro.re/higepi/M2_SETI
This commit is contained in:
commit
f1ebf554d1
1 changed files with 40 additions and 14 deletions
|
@ -10,12 +10,9 @@
|
|||
#include "multitaskingAccumulator.h"
|
||||
#include "iAcquisitionManager.h"
|
||||
#include "debug.h"
|
||||
|
||||
|
||||
//producer count storage
|
||||
_Atomic int produceCount = 0;
|
||||
|
||||
// volatile unsigned int producedCount = 0;
|
||||
#include <stdatomic.h>
|
||||
#include <sys/syscall.h>
|
||||
#define gettid() syscall(SYS_gettid)
|
||||
|
||||
pthread_t producers[4];
|
||||
|
||||
|
@ -36,9 +33,18 @@ sem_t semaphore_occupe;
|
|||
* Usefull variables
|
||||
*/
|
||||
|
||||
MSG_BLOCK Buffer[BUFFER_SIZE];
|
||||
_Atomic int index_libre = 0;
|
||||
_Atomic int thread_count = 0;
|
||||
|
||||
|
||||
//producer count storage
|
||||
_Atomic int verrou = 0;
|
||||
volatile unsigned int produceCount = 0;
|
||||
|
||||
|
||||
|
||||
|
||||
/*
|
||||
* Creates the synchronization elements.
|
||||
* @return ERROR_SUCCESS if the init is ok, ERROR_INIT otherwise
|
||||
|
@ -50,6 +56,22 @@ static unsigned int createSynchronizationObjects(void);
|
|||
*/
|
||||
static void incrementProducedCount(void);
|
||||
|
||||
// Méthode pour verrouiller un accès
|
||||
static void pCountLockTake(){
|
||||
int expected = 0;
|
||||
|
||||
//Tant que verrou ne vaut pas 0, on attend et expected vaut 0. Si verrou vaut bien 0, on le met à 1
|
||||
while(!atomic_compare_exchange_weak(&verrou, &expected, 1))
|
||||
expected = 0;
|
||||
|
||||
//La fonction se termine..
|
||||
}
|
||||
|
||||
// Méthode pour libérer un accès
|
||||
static void pCountLockRelease(){
|
||||
verrou = 1;
|
||||
}
|
||||
|
||||
static unsigned int createSynchronizationObjects(void)
|
||||
{
|
||||
int error;
|
||||
|
@ -71,16 +93,20 @@ static unsigned int createSynchronizationObjects(void)
|
|||
|
||||
static void incrementProducedCount(void)
|
||||
{
|
||||
//TODO
|
||||
produceCount++;
|
||||
//On incrément le nombre de threads producteurs
|
||||
pCountLockTake();
|
||||
produceCount++;
|
||||
pCountLockRelease();
|
||||
}
|
||||
|
||||
unsigned int getProducedCount(void)
|
||||
{
|
||||
unsigned int p = 0;
|
||||
//TODO
|
||||
p = produceCount;
|
||||
return p;
|
||||
unsigned int p = 0;
|
||||
//On crée une section actomique
|
||||
pCountLockTake();
|
||||
p = produceCount;
|
||||
pCountLockRelease();
|
||||
return p;
|
||||
}
|
||||
|
||||
|
||||
|
@ -161,7 +187,7 @@ void *produce(void* params)
|
|||
|
||||
sem_post(&semaphore_occupe);
|
||||
}
|
||||
printf("[acquisitionManager] %d termination\n", gettid());
|
||||
printf("[acquisitionManager] %d termination\n", syscall(gettid()));
|
||||
//TODO
|
||||
pthread_exit(NULL);
|
||||
}
|
Loading…
Reference in a new issue