Kernel icon indicating copy to clipboard operation
Kernel copied to clipboard

IPC primitives

Open Frityet opened this issue 2 years ago • 0 comments

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);

Frityet avatar Apr 23 '23 05:04 Frityet