Kernel Objects and Watchers
Semaphore
Semaphore are important in the concept of kernel objects and watchers. There main purpose is thread blocking. In order to wake unblock a thread the blocker either needs to be interrupted or receive a signal. This signal is not the same as a signal used in LIBC.
Basic Semaphore Blocker Definition:
class SemaphoreBlocker : public ThreadBlocker{
friend class Semaphore;
public:
SemaphoreBlocker* next = nullptr;
SemaphoreBlocker* prev = nullptr;
Semaphore* semaphore = nullptr;
inline SemaphoreBlocker(Semaphore* sema) : semaphore(sema) {
}
void Interrupt(){
interrupted = true;
shouldBlock = false;
acquireLock(&lock);
if(semaphore){
semaphore->blocked.remove(this);
semaphore = nullptr;
}
if(thread){
thread->Unblock();
}
thread = nullptr;
releaseLock(&lock);
}
void Unblock(){
shouldBlock = false;
acquireLock(&lock);
if(semaphore){
semaphore->blocked.remove(this);
}
semaphore = nullptr;
if(thread){
thread->Unblock();
}
releaseLock(&lock);
}
~SemaphoreBlocker(){
if(semaphore){
semaphore->blocked.remove(this);
}
}
};
Currently the main use of a semaphore is to aid in the Syscall Sleep function as it can block a thread from running. And also to await for a reply from a message.
Kernel Objects
A kernel object is a object that is used towards Processes. This can be MessageEnpoints, Interfaces, Services or Processes themselves.
Processes can watch other processes.
Last updated