Try setting global semaphores as non-static

This commit is contained in:
zenon 2018-06-08 12:28:57 +02:00
parent ac4559ab26
commit 255708ebc0
2 changed files with 15 additions and 13 deletions

View File

@ -13,13 +13,13 @@ static const char *pname;
static struct circ_buf *shared; static struct circ_buf *shared;
static int shmfd; int shmfd;
static sem_t *sUsedSpace; sem_t *sUsedSpace;
static sem_t *sFreeSpace; sem_t *sFreeSpace;
static sem_t *sWriteEnd; sem_t *sWriteEnd;
struct sigaction sa; struct sigaction sa;
@ -223,6 +223,9 @@ void wait_sem(sem_t *sem)
void putSolution(int *solution) void putSolution(int *solution)
{ {
if (shared->quit == 1)
return;
wait_sem(sWriteEnd); wait_sem(sWriteEnd);
for (int i = 0; i < MAX_ITEMS; i++) { for (int i = 0; i < MAX_ITEMS; i++) {

View File

@ -12,13 +12,13 @@ static const char *pname;
struct circ_buf *shared; struct circ_buf *shared;
static int shmfd; int shmfd;
static sem_t *sUsedSpace; sem_t *sUsedSpace;
static sem_t *sFreeSpace; sem_t *sFreeSpace;
static sem_t *sWriteEnd; sem_t *sWriteEnd;
struct sigaction sa; struct sigaction sa;
@ -121,12 +121,11 @@ void getSolution(sem_t *sUsedSpace, sem_t *sFreeSpace)
// Compute length of newSolution // Compute length of newSolution
if (solution[0] != -1) { if (solution[0] != -1) {
for (int i = 0; i < MAX_ITEMS; i++) { int i = 0;
if (solution[i] == -1) { while ((solution[i] != -1) && (i != (MAX_ITEMS - 1))) {
newSolutionLength = i; i++;
break;
}
} }
newSolutionLength = i;
} }
if (newSolutionLength == 0) { if (newSolutionLength == 0) {