2022-04-06 04:53:57 +00:00
|
|
|
#include <semaphore.h> // POSIX semaphores!
|
2022-04-05 20:37:42 +00:00
|
|
|
#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 *) {
|
2022-04-06 04:53:57 +00:00
|
|
|
block *c;
|
2022-04-05 01:12:40 +00:00
|
|
|
while (true) {
|
2022-04-06 04:15:51 +00:00
|
|
|
// wait for element on list2
|
2022-04-05 20:37:42 +00:00
|
|
|
wait(sem_list2);
|
2022-04-06 04:15:51 +00:00
|
|
|
// mutual exclusion for list2
|
2022-04-05 20:37:42 +00:00
|
|
|
wait(mut_list2);
|
2022-04-06 03:30:46 +00:00
|
|
|
//* c:=unlink(list-2);
|
|
|
|
c = unlink(list2);
|
2022-04-06 04:15:51 +00:00
|
|
|
// mutual exclusion for list2
|
2022-04-05 20:37:42 +00:00
|
|
|
signal(mut_list2);
|
|
|
|
|
2022-04-06 03:30:46 +00:00
|
|
|
//* consume_information_in_block(c)
|
2022-04-05 01:12:40 +00:00
|
|
|
consume(c);
|
2022-04-05 20:37:42 +00:00
|
|
|
|
2022-04-06 04:15:51 +00:00
|
|
|
// mutual exclusion for freelist
|
2022-04-05 20:37:42 +00:00
|
|
|
wait(mut_freelist);
|
2022-04-06 03:30:46 +00:00
|
|
|
//* link(c, freelist)
|
|
|
|
link(c, freelist);
|
2022-04-06 04:15:51 +00:00
|
|
|
// mutual exclusion for freelist
|
2022-04-05 20:37:42 +00:00
|
|
|
signal(mut_freelist);
|
2022-04-06 04:15:51 +00:00
|
|
|
// signal thread-1 to continue
|
|
|
|
signal(sem_freelist_minus_1);
|
|
|
|
// signal new element on freelist
|
2022-04-05 20:37:42 +00:00
|
|
|
signal(sem_freelist);
|
2022-04-05 01:12:40 +00:00
|
|
|
}
|
|
|
|
return nullptr;
|
|
|
|
}
|
|
|
|
|
|
|
|
int consume(block *c) {
|
2022-04-06 04:15:51 +00:00
|
|
|
return 0;
|
2022-04-05 01:12:40 +00:00
|
|
|
}
|