TheLuaOSProject / Kernel

Kernel for the LuaOS operating system
GNU General Public License v3.0
36 stars 4 forks source link

IPC primitives #25

Open Frityet opened 1 year ago

Frityet commented 1 year ago

With a proper scheduler and processes be implemented by @pitust (d82913c2185522739286bf05c0cf6deb491314f5) IPC is needed for the userland to be able to be worked on.

The idea is something like

struct Channel {
    struct Message {
        struct Message *nullable next, *nullable previous;
        size_t length;
        byte data[];
    };

    struct Message *nonnull read_head, *nonnull write_head;
    size_t byte_count, byte_max;
    size_t message_count, message_max;
};

typedef struct PrimitiveMutex {
    struct Thread *nonnull head;
} PrimitiveMutex;

typedef struct Thread {
    char name[64];
    CPUContext ctx;
    void *stack_base;
    struct Thread *nullable next_task, *nullable previous_task;
    lua_State *nonnull lua;
    bool ready, kill;
    atomic(bool) lock;

    struct Thread *nullable next_mutex;
    PrimitiveMutex mutex;
} Thread;

int wait_for_thread(Thread *nonnull thread)
int wake_mutex(PrimitiveMutex *nonnull mtx);
int wake_all_mutexes(PrimitiveMutex *nonnull mutexes);