From 2e79a2e5af3affa7a6a3becdffb1c91d89af90af Mon Sep 17 00:00:00 2001 From: dzwdz Date: Mon, 11 Jul 2022 21:54:51 +0200 Subject: user: reorganize the userland sources --- src/init/lib/esemaphore.c | 55 ----------------------------------------------- src/init/lib/esemaphore.h | 12 ----------- 2 files changed, 67 deletions(-) delete mode 100644 src/init/lib/esemaphore.c delete mode 100644 src/init/lib/esemaphore.h (limited to 'src/init/lib') diff --git a/src/init/lib/esemaphore.c b/src/init/lib/esemaphore.c deleted file mode 100644 index ac65b02..0000000 --- a/src/init/lib/esemaphore.c +++ /dev/null @@ -1,55 +0,0 @@ -#include -#include -#include -#include - -void esem_signal(struct evil_sem *sem) { - _syscall_write(sem->signal, NULL, 0, 0); -} - -void esem_wait(struct evil_sem *sem) { - _syscall_read(sem->wait, NULL, 0, 0); -} - -struct evil_sem *esem_new(int value) { - handle_t ends_wait[2], ends_signal[2]; - struct evil_sem *sem; - - if (value < 0) return NULL; - if (_syscall_pipe(ends_wait, 0) < 0) return NULL; - if (_syscall_pipe(ends_signal, 0) < 0) goto fail_signal; - if (!(sem = malloc(sizeof *sem))) goto fail_malloc; - - if (!_syscall_fork(FORK_NOREAP, NULL)) { - _syscall_close(ends_signal[1]); - while (_syscall_read(ends_signal[0], NULL, 0, 0) >= 0) { - if (!_syscall_fork(FORK_NOREAP, NULL)) { - _syscall_write(ends_wait[1], NULL, 0, 0); - _syscall_exit(0); - } - } - _syscall_exit(0); - } - _syscall_close(ends_signal[0]); - _syscall_close(ends_wait[1]); - - sem->wait = ends_wait[0]; - sem->signal = ends_signal[1]; - - while (value--) esem_signal(sem); - return sem; - -fail_malloc: - _syscall_close(ends_signal[0]); - _syscall_close(ends_signal[1]); -fail_signal: - _syscall_close(ends_wait[0]); - _syscall_close(ends_wait[1]); - return NULL; -} - -void esem_free(struct evil_sem *sem) { - _syscall_close(sem->wait); - _syscall_close(sem->signal); - free(sem); -} diff --git a/src/init/lib/esemaphore.h b/src/init/lib/esemaphore.h deleted file mode 100644 index e746bd7..0000000 --- a/src/init/lib/esemaphore.h +++ /dev/null @@ -1,12 +0,0 @@ -#pragma once -#include - -struct evil_sem { - handle_t wait, signal; -}; - -void esem_signal(struct evil_sem *sem); -void esem_wait(struct evil_sem *sem); - -struct evil_sem *esem_new(int value); -void esem_free(struct evil_sem *sem); -- cgit v1.2.3