Read and write solution characterwise
This commit is contained in:
parent
eb45b4eb92
commit
10ec964fec
14
generator.c
14
generator.c
@ -170,21 +170,13 @@ void printGraph()
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
void putSolution(sem_t sUsedSpace, sem_t sFreeSpace, sem_t sWriteEnd, int *solution)
|
void putItem(sem_t sUsedSpace, sem_t sFreeSpace, sem_t sWriteEnd, int value)
|
||||||
{
|
{
|
||||||
sem_wait(&sWriteEnd);
|
sem_wait(&sWriteEnd);
|
||||||
sem_wait(&sFreeSpace);
|
sem_wait(&sFreeSpace);
|
||||||
|
|
||||||
if (solution[0] == -1) {
|
shared->data[shared->tail] = -1;
|
||||||
shared->data[shared->tail] = -1;
|
shared->tail = (shared->tail + 1) % MAX_ITEMS;
|
||||||
shared->tail = (shared->tail + 1) % MAX_ITEMS;
|
|
||||||
}
|
|
||||||
|
|
||||||
int i = 0;
|
|
||||||
while (solution[i] != -1) {
|
|
||||||
shared->data[shared->tail] = solution[i];
|
|
||||||
shared->tail = (shared->tail + 1) % MAX_ITEMS;
|
|
||||||
}
|
|
||||||
|
|
||||||
sem_post(&sUsedSpace);
|
sem_post(&sUsedSpace);
|
||||||
sem_post(&sWriteEnd);
|
sem_post(&sWriteEnd);
|
||||||
|
|||||||
@ -36,7 +36,7 @@ void initCircBuf()
|
|||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
int getSolution(sem_t sUsedSpace, sem_t sFreeSpace, int *solution)
|
int getItem(sem_t sUsedSpace, sem_t sFreeSpace)
|
||||||
{
|
{
|
||||||
sem_wait(&sUsedSpace);
|
sem_wait(&sUsedSpace);
|
||||||
|
|
||||||
|
|||||||
Loading…
x
Reference in New Issue
Block a user