diff options
Diffstat (limited to 'src/loop')
| -rw-r--r-- | src/loop/CMakeLists.txt | 20 | ||||
| -rw-r--r-- | src/loop/include/loop.h | 28 | ||||
| -rw-r--r-- | src/loop/private_include/loop/types.h | 26 | ||||
| -rw-r--r-- | src/loop/src/CMakeLists.txt | 21 | ||||
| -rw-r--r-- | src/loop/src/add_aio.c | 43 | ||||
| -rw-r--r-- | src/loop/src/rm_aio.c | 48 | ||||
| -rw-r--r-- | src/loop/src/run.c | 33 |
7 files changed, 219 insertions, 0 deletions
diff --git a/src/loop/CMakeLists.txt b/src/loop/CMakeLists.txt new file mode 100644 index 0000000..4645d01 --- /dev/null +++ b/src/loop/CMakeLists.txt @@ -0,0 +1,20 @@ +# wanix, a Unix-like operating system for WebAssembly applications. +# Copyright (C) 2025 Xavier Del Campo Romero +# +# This program is free software: you can redistribute it and/or modify +# it under the terms of the GNU Affero General Public License as published by +# the Free Software Foundation, either version 3 of the License, or +# (at your option) any later version. +# +# This program is distributed in the hope that it will be useful, +# but WITHOUT ANY WARRANTY; without even the implied warranty of +# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the +# GNU Affero General Public License for more details. +# +# You should have received a copy of the GNU Affero General Public License +# along with this program. If not, see <https://www.gnu.org/licenses/>. + +add_library(loop) +add_subdirectory(src) +target_include_directories(loop PUBLIC include PRIVATE private_include) +target_link_libraries(loop PUBLIC aio PRIVATE fs init) diff --git a/src/loop/include/loop.h b/src/loop/include/loop.h new file mode 100644 index 0000000..dd833d1 --- /dev/null +++ b/src/loop/include/loop.h @@ -0,0 +1,28 @@ +/* + * wanix, a Unix-like operating system for WebAssembly applications. + * Copyright (C) 2025 Xavier Del Campo Romero + * + * This program is free software: you can redistribute it and/or modify + * it under the terms of the GNU Affero General Public License as published by + * the Free Software Foundation, either version 3 of the License, or + * (at your option) any later version. + * + * This program is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU Affero General Public License for more details. + * + * You should have received a copy of the GNU Affero General Public License + * along with this program. If not, see <https://www.gnu.org/licenses/>. + */ + +#ifndef LOOP_H +#define LOOP_H + +#include <aio.h> + +int loop_run(void); +int loop_add_aio(struct aio *a); +int loop_rm_aio(struct aio *a); + +#endif diff --git a/src/loop/private_include/loop/types.h b/src/loop/private_include/loop/types.h new file mode 100644 index 0000000..d42a042 --- /dev/null +++ b/src/loop/private_include/loop/types.h @@ -0,0 +1,26 @@ +/* + * wanix, a Unix-like operating system for WebAssembly applications. + * Copyright (C) 2025 Xavier Del Campo Romero + * + * This program is free software: you can redistribute it and/or modify + * it under the terms of the GNU Affero General Public License as published by + * the Free Software Foundation, either version 3 of the License, or + * (at your option) any later version. + * + * This program is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU Affero General Public License for more details. + * + * You should have received a copy of the GNU Affero General Public License + * along with this program. If not, see <https://www.gnu.org/licenses/>. + */ + +#ifndef LOOP_TYPES_H +#define LOOP_TYPES_H + +#include <aio.h> + +struct aio_poll *loop_aio_head, *loop_aio_tail; + +#endif diff --git a/src/loop/src/CMakeLists.txt b/src/loop/src/CMakeLists.txt new file mode 100644 index 0000000..ab55275 --- /dev/null +++ b/src/loop/src/CMakeLists.txt @@ -0,0 +1,21 @@ +# wanix, a Unix-like operating system for WebAssembly applications. +# Copyright (C) 2025 Xavier Del Campo Romero +# +# This program is free software: you can redistribute it and/or modify +# it under the terms of the GNU Affero General Public License as published by +# the Free Software Foundation, either version 3 of the License, or +# (at your option) any later version. +# +# This program is distributed in the hope that it will be useful, +# but WITHOUT ANY WARRANTY; without even the implied warranty of +# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the +# GNU Affero General Public License for more details. +# +# You should have received a copy of the GNU Affero General Public License +# along with this program. If not, see <https://www.gnu.org/licenses/>. + +target_sources(loop PRIVATE + add_aio.c + rm_aio.c + run.c +) diff --git a/src/loop/src/add_aio.c b/src/loop/src/add_aio.c new file mode 100644 index 0000000..8174acc --- /dev/null +++ b/src/loop/src/add_aio.c @@ -0,0 +1,43 @@ +/* + * wanix, a Unix-like operating system for WebAssembly applications. + * Copyright (C) 2025 Xavier Del Campo Romero + * + * This program is free software: you can redistribute it and/or modify + * it under the terms of the GNU Affero General Public License as published by + * the Free Software Foundation, either version 3 of the License, or + * (at your option) any later version. + * + * This program is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU Affero General Public License for more details. + * + * You should have received a copy of the GNU Affero General Public License + * along with this program. If not, see <https://www.gnu.org/licenses/>. + */ + +#include <loop.h> +#include <loop/types.h> +#include <aio.h> +#include <stdlib.h> + +int loop_add_aio(struct aio *const a) +{ + struct aio_poll *const p = malloc(sizeof *p); + + if (!p) + return -1; + + *p = (const struct aio_poll){.aio = a}; + + if (!loop_aio_head) + loop_aio_head = p; + else if (loop_aio_tail) + { + loop_aio_tail->next = p; + p->prev = loop_aio_tail; + } + + loop_aio_tail = p; + return 0; +} diff --git a/src/loop/src/rm_aio.c b/src/loop/src/rm_aio.c new file mode 100644 index 0000000..b6c678a --- /dev/null +++ b/src/loop/src/rm_aio.c @@ -0,0 +1,48 @@ +/* + * wanix, a Unix-like operating system for WebAssembly applications. + * Copyright (C) 2025 Xavier Del Campo Romero + * + * This program is free software: you can redistribute it and/or modify + * it under the terms of the GNU Affero General Public License as published by + * the Free Software Foundation, either version 3 of the License, or + * (at your option) any later version. + * + * This program is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU Affero General Public License for more details. + * + * You should have received a copy of the GNU Affero General Public License + * along with this program. If not, see <https://www.gnu.org/licenses/>. + */ + +#include <loop.h> +#include <loop/types.h> +#include <aio.h> +#include <stdlib.h> + +int loop_rm_aio(struct aio *const aio) +{ + for (struct aio_poll *p = loop_aio_head; p; p = p->next) + if (p->aio == aio) + { + struct aio_poll *const prev = p->prev, *const next = p->next; + + if (!prev) + { + loop_aio_head = next; + + if (next) + next->prev = NULL; + } + else if ((prev->next = next)) + next->prev = prev; + else + loop_aio_tail = prev; + + free(p); + return 0; + } + + return -1; +} diff --git a/src/loop/src/run.c b/src/loop/src/run.c new file mode 100644 index 0000000..666aa33 --- /dev/null +++ b/src/loop/src/run.c @@ -0,0 +1,33 @@ +/* + * wanix, a Unix-like operating system for WebAssembly applications. + * Copyright (C) 2025 Xavier Del Campo Romero + * + * This program is free software: you can redistribute it and/or modify + * it under the terms of the GNU Affero General Public License as published by + * the Free Software Foundation, either version 3 of the License, or + * (at your option) any later version. + * + * This program is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU Affero General Public License for more details. + * + * You should have received a copy of the GNU Affero General Public License + * along with this program. If not, see <https://www.gnu.org/licenses/>. + */ + +#include <loop.h> +#include <loop/types.h> +#include <aio.h> +#include <fs/fs.h> +#include <init.h> + +int loop_run(void) +{ + if (fs_update() + || aio_poll(loop_aio_head, 0) < 0 + || init_run()) + return -1; + + return 0; +} |
