class semaphore {
private:
int value;
list<PCB> wait_list;
public:
semaphore() {
value = 0;
wait_list = list<PCB>();
}
semaphore(int a) {
value = a;
wait_list = list<PCB>();
} |
void wait(void) {
value--;
if (value < 0) { wait_list.push_front(
current);
sleep();
}
}
void signal(void) {
PCB p;
value++;
if (value <=0) {
p = *(wait_list.end()); wait_list.pop_back();
wakeup(p);
}
}
} |