4600-project-1/src/consumer.cpp

34 lines
634 B
C++
Raw Normal View History

2022-04-05 01:12:40 +00:00
#include <semaphore.h>
#include <unistd.h>
#include "list.hpp" // list implementation
#include "globals.hpp" // lists, sems, muts
2022-04-04 18:39:30 +00:00
#include "consumer.hpp"
2022-04-05 01:12:40 +00:00
int consume(block* c);
void *consumer (void *) {
block* c;
2022-04-05 01:12:40 +00:00
while (true) {
wait(sem_list2);
wait(mut_list2);
//* c:=unlink(list-2);
c = unlink(list2);
signal(mut_list2);
//* consume_information_in_block(c)
2022-04-05 01:12:40 +00:00
consume(c);
wait(mut_freelist);
//* link(c, freelist)
link(c, freelist);
signal(mut_freelist);
signal(sem_freelist);
2022-04-05 01:12:40 +00:00
}
return nullptr;
}
int consume(block *c) {
return c->data;
2022-04-05 01:12:40 +00:00
}