diff --git a/common.h b/common.h index 38112a7..6299200 100644 --- a/common.h +++ b/common.h @@ -35,13 +35,12 @@ #define SEM_WRITE_END "/write_end_01527193" #define MAX_ITEMS 16 -#define CIRC_BUF_SIZE 17 struct circ_buf { int quit; int head; int tail; - int data[CIRC_BUF_SIZE]; + int data[MAX_ITEMS]; }; #endif /* ifndef COMMON_H */ diff --git a/generator.c b/generator.c index a4e3f76..761082c 100644 --- a/generator.c +++ b/generator.c @@ -228,14 +228,14 @@ void putSolution(int *solution) if (solution[0] == -1) { wait_sem(sFreeSpace); shared->data[shared->tail] = -1; - shared->tail = (shared->tail + 1) % CIRC_BUF_SIZE; + shared->tail = (shared->tail + 1) % MAX_ITEMS; sem_post(sUsedSpace); } else { int i = 0; while (solution[i] != -1) { wait_sem(sFreeSpace); shared->data[shared->tail] = solution[i]; - shared->tail = (shared->tail + 1) % CIRC_BUF_SIZE; + shared->tail = (shared->tail + 1) % MAX_ITEMS; sem_post(sUsedSpace); i++; } diff --git a/supervisor.c b/supervisor.c index 34fb04e..fa6fdeb 100644 --- a/supervisor.c +++ b/supervisor.c @@ -62,7 +62,7 @@ void cleanup() void initCircBuf() { shared->quit = 0; - for (int i = 0; i < CIRC_BUF_SIZE; i++) { + for (int i = 0; i < MAX_ITEMS; i++) { shared->data[i] = -1; } return; @@ -92,9 +92,7 @@ void getSolution(sem_t *sUsedSpace, sem_t *sFreeSpace) } if (shared->data[shared->head] == -1) { - wait_sem(sUsedSpace); shared->head = (shared->head + 1) % MAX_ITEMS; - sem_post(sFreeSpace); } else { int i = 0; while (shared->data[shared->head] != -1) {