Unified-OS
  • #️Unified OS
  • 🚀Getting Started
    • Installation
    • Booting
  • Architecture
    • Overview
    • ACPI
    • APIC
    • Constructors
    • ELF - Executables
    • Higher Kernel
    • IDT (Interrupts)
    • IPC
    • Kernel Objects and Watchers
    • Memory Management
    • PCI
    • PIT
    • Scheduling
    • Serial
    • Signals
    • SMP
    • Spinlocks
    • Syscalls
    • UFEI Bootloader and Setup
  • Drivers
    • SATA
    • Video
  • Other
    • FAT-32
    • Filesystem
    • Heap
    • Page
  • Processes
    • Libraries
      • MLibc
      • Libunified
    • OS-Based Processes
      • Daemon
      • Window Manager
  • Contributing
    • Contributing
Powered by GitBook
On this page
  • Semaphore
  • Kernel Objects
  1. Architecture

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.

PreviousIPCNextMemory Management

Last updated 1 year ago