adapt to vector
This commit is contained in:
@ -11,7 +11,7 @@ void Semaphore::p() {
|
||||
this->lock.release();
|
||||
} else {
|
||||
// Block and manage thread in semaphore queue until it's woken up by v() again
|
||||
this->waitQueue.insert_last(scheduler.get_active());
|
||||
this->waitQueue.push_back(scheduler.get_active());
|
||||
this->lock.release();
|
||||
scheduler.block(); // Moves to next thread
|
||||
}
|
||||
@ -22,13 +22,12 @@ void Semaphore::v() {
|
||||
|
||||
if (!this->waitQueue.empty()) {
|
||||
// Semaphore stays busy and unblocks next thread to work in critical section
|
||||
Thread* next = this->waitQueue.remove_first().value_or(nullptr);
|
||||
if (next == nullptr) {
|
||||
// TODO: Log this once the logger is static
|
||||
if (this->waitQueue.empty()) {
|
||||
this->lock.release();
|
||||
return;
|
||||
}
|
||||
|
||||
Thread* next = this->waitQueue[0];
|
||||
this->waitQueue.erase(waitQueue.begin());
|
||||
this->lock.release();
|
||||
scheduler.deblock(next);
|
||||
} else {
|
||||
|
||||
@ -13,15 +13,14 @@
|
||||
|
||||
#include "kernel/threads/Thread.h"
|
||||
#include "lib/SpinLock.h"
|
||||
#include "user/lib/ArrayList.h"
|
||||
#include "user/lib/Vector.h"
|
||||
|
||||
class Semaphore {
|
||||
|
||||
private:
|
||||
Semaphore(const Semaphore& copy) = delete; // Verhindere Kopieren
|
||||
|
||||
// Queue fuer wartende Threads.
|
||||
ArrayList<Thread*> waitQueue;
|
||||
bse::Vector<Thread*> waitQueue;
|
||||
SpinLock lock;
|
||||
|
||||
int counter;
|
||||
|
||||
Reference in New Issue
Block a user