Initial semaphore test
This commit is contained in:
parent
8dbd116b88
commit
49357d1173
13
supervisor.c
13
supervisor.c
@ -29,9 +29,6 @@ void usage(void)
|
|||||||
|
|
||||||
void initCircBuf()
|
void initCircBuf()
|
||||||
{
|
{
|
||||||
shared->validItems = 0;
|
|
||||||
shared->head = 0;
|
|
||||||
shared->tail = 0;
|
|
||||||
shared->quit = 0;
|
shared->quit = 0;
|
||||||
for (int i = 0; i < MAX_ITEMS; i++) {
|
for (int i = 0; i < MAX_ITEMS; i++) {
|
||||||
shared->data[i] = 0;
|
shared->data[i] = 0;
|
||||||
@ -47,16 +44,16 @@ int isEmpty()
|
|||||||
return 0;
|
return 0;
|
||||||
}
|
}
|
||||||
|
|
||||||
int getItem()
|
int getSolution(sem_t sUsedSpace, sem_t sFreeSpace, int *solution)
|
||||||
{
|
{
|
||||||
if (isEmpty())
|
sem_wait(&sUsedSpace);
|
||||||
return -1;
|
|
||||||
|
|
||||||
int value;
|
int value;
|
||||||
|
|
||||||
value = shared->data[shared->head];
|
value = shared->data[shared->head];
|
||||||
shared->head = (shared->head + 1) % MAX_ITEMS;
|
shared->head = (shared->head + 1) % MAX_ITEMS;
|
||||||
shared->validItems--;
|
|
||||||
|
sem_post(&sFreeSpace);
|
||||||
|
|
||||||
return value;
|
return value;
|
||||||
}
|
}
|
||||||
@ -95,6 +92,8 @@ int main(int argc, char *argv[])
|
|||||||
initCircBuf();
|
initCircBuf();
|
||||||
|
|
||||||
while (quit == 0) {
|
while (quit == 0) {
|
||||||
|
int solution[MAX_ITEMS] = {-1};
|
||||||
|
getSolution(*sUsedSpace, *sFreeSpace, solution);
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
Loading…
x
Reference in New Issue
Block a user