Change MAX_ITEMS to CIRC_BUF_SIZE for shared memory access
This commit is contained in:
parent
ed71c16797
commit
a7ebeb7246
@ -177,14 +177,14 @@ void putSolution(sem_t sUsedSpace, sem_t sFreeSpace, sem_t sWriteEnd, int *solut
|
|||||||
if (solution[0] == -1) {
|
if (solution[0] == -1) {
|
||||||
sem_wait(&sFreeSpace);
|
sem_wait(&sFreeSpace);
|
||||||
shared->data[shared->tail] = -1;
|
shared->data[shared->tail] = -1;
|
||||||
shared->tail = (shared->tail + 1) % MAX_ITEMS;
|
shared->tail = (shared->tail + 1) % CIRC_BUF_SIZE;
|
||||||
sem_post(&sUsedSpace);
|
sem_post(&sUsedSpace);
|
||||||
} else {
|
} else {
|
||||||
int i = 0;
|
int i = 0;
|
||||||
while (solution[i] != -1) {
|
while (solution[i] != -1) {
|
||||||
sem_wait(&sFreeSpace);
|
sem_wait(&sFreeSpace);
|
||||||
shared->data[shared->tail] = solution[i];
|
shared->data[shared->tail] = solution[i];
|
||||||
shared->tail = (shared->tail + 1) % MAX_ITEMS;
|
shared->tail = (shared->tail + 1) % CIRC_BUF_SIZE;
|
||||||
sem_post(&sUsedSpace);
|
sem_post(&sUsedSpace);
|
||||||
i++;
|
i++;
|
||||||
}
|
}
|
||||||
|
|||||||
Loading…
x
Reference in New Issue
Block a user