| 12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273 |
- #include <stdbool.h>
- #include <stddef.h>
- #ifndef ZIVUOS_DISABLE_DYNAMIC
- #include <malloc.h>
- #endif
- #include "process.h"
- #include "kernel.h"
- #include "models.h"
- #include "state.h"
- #ifndef ZV_ALLOC_STEP
- #define ZV_ALLOC_STEP 0x08
- #endif
- void zv_kernel_init(
- zv_kernel_t *self,
- zv_process_t **processes,
- zv_pid_t processes_count
- ) {
- self->processes_stack = processes;
- self->processes_stack_size = processes_count;
- #ifndef ZIVUOS_DISABLE_DYNAMIC
- self->is_dynamic = false;
- #endif
- }
- zv_pid_t zv_kernel_count_processes(zv_kernel_t *self) {
- zv_pid_t result = 0;
- for (zv_pid_t count = 0; count < self->processes_stack_size; ++count) {
- if (self->processes_stack[count] == NULL) {
- continue;
- }
- ++result;
- }
- return result;
- }
- #ifndef ZIVUOS_DISABLE_DYNAMIC
- static inline size_t zv_get_stack_size(zv_pid_t count) {
- return (count * sizeof(zv_process_t *));
- }
- zv_kernel_t * zv_kernel_create() {
- zv_kernel_t *self = (zv_kernel_t *) malloc(sizeof(zv_kernel_t));
-
- if (self == NULL) {
- return NULL;
- }
- #define STACK_SIZE zv_get_stack_size(ZV_ALLOC_STEP)
- zv_process_t **stack = (zv_process_t **) malloc(STACK_SIZE);
- #undef STACK_SIZE
- if (stack == NULL) {
- free(self);
- return NULL;
- }
- zv_kernel_init(self, stack, ZV_ALLOC_STEP);
- self->is_dynamic = true;
- return self;
- }
- #endif
|