Taiga Develop 6 tháng trước cách đây
mục cha
commit
923e3e9bec

+ 5 - 0
headers/zivuos.h

@@ -4,5 +4,10 @@
 #include "zivuos/kernel.h"
 #include "zivuos/models.h"
 #include "zivuos/process.h"
+#include "zivuos/result.h"
+#include "zivuos/scheduler.h"
+#include "zivuos/alloc.h"
+#include "zivuos/vector.h"
+#include "zivuos/vector_helpers.h"
 
 #endif

+ 0 - 0
headers/zivuos/alloc.c


+ 14 - 0
headers/zivuos/alloc.h

@@ -0,0 +1,14 @@
+#ifndef CX_ZIVUOS_ALLOC_H_INCLUDED
+#define CX_ZIVUOS_ALLOC_H_INCLUDED
+
+#include <stddef.h>
+#include <stdint.h>
+#include <stdbool.h>
+
+void * zv_alloc(size_t);
+void * zv_alloc_zero(size_t);
+void zv_free(void *);
+
+#define ZV_ALLOC_USE_STDLIB
+
+#endif

+ 2 - 1
headers/zivuos/kernel.h

@@ -33,7 +33,8 @@ zv_pid_t zv_kernel_add_process(
 );
 
 void __zv_kernel_clean_balance(zv_kernel_t *);
-void zv_idle_task();
+void zv_kernel_idle_task();
+bool zv_kernel_set_scheduler(zv_kernel_t *, zv_scheduler_mode_t);
 zv_result_t zv_kernel_trigger_process(zv_kernel_t *, zv_pid_t);
 
 static inline zv_process_t * __zv_kernel_get_process(

+ 1 - 1
headers/zivuos/models.h

@@ -20,7 +20,7 @@ typedef union zv_universal_u {
     uintptr_t unumber;
     intptr_t number;
     void *pointer;
-    char *string;
+    char *cstring;
 } zv_universal_t;
 
 struct zv_kernel_s;

+ 4 - 2
headers/zivuos/process.h

@@ -4,6 +4,7 @@
 #include <stdint.h>
 #include <stdbool.h>
 
+#include "result.h"
 #include "models.h"
 
 typedef struct zv_process_s {
@@ -26,8 +27,9 @@ static inline zv_priority_t _zv_process_calc_priority(zv_process_t *self) {
     return self->priority + self->balance;
 }
 
-zv_result_t zv_process_change_param(zv_process_t *, zv_universal_t);
-zv_result_t zv_process_change_worker(zv_process_t *, zv_worker_t);
+zv_result_t zv_process_set_param(zv_process_t *, zv_universal_t);
+zv_result_t zv_process_set_worker(zv_process_t *, zv_worker_t);
+zv_result_t zv_process_set_priority(zv_process_t *, zv_priority_t);
 
 #define ZV_COUNT_PROCESSES(X) ((sizeof(X) / sizeof(zv_process_t)))
 

+ 35 - 0
headers/zivuos/vector.h

@@ -0,0 +1,35 @@
+#ifndef CX_ZIVUOS_VECTOR_H_INCLUDED
+#define CX_ZIVUOS_VECTOR_H_INCLUDED
+
+#include <stdint.h>
+#include <stddef.h>
+#include <stdbool.h>
+
+#include "result.h"
+#include "models.h"
+
+struct zv_vector_s;
+struct zv_vector_container_s;
+
+typedef struct zv_vector_s {
+    size_t lenght;
+    struct zv_vectos_container_s *first;
+    struct zv_vector_container_s *last;
+} zv_vector_t;
+
+typedef struct zv_vector_container_s {
+    struct zv_vector_container_s *previous;
+    struct zv_vector_container_s *next;
+    zv_universal_t content;
+} zv_vector_container_t;
+
+zv_vector_t * zv_vector_create();
+zv_universal_t zv_vector_get(zv_vector_t *, size_t);
+size_t zv_vector_push(zv_vector_t *, zv_universal_t);
+size_t zv_vector_count(zv_vector_t *);
+zv_universal_t zv_vector_pop(zv_vector_t *, size_t);
+bool zv_vector_insert(zv_vector_t *, zv_universal_t, size_t);
+void zv_vector_remove(zv_vector_t *);
+zv_universal_t * zv_vector_to_array(zv_vector_t *);
+
+#endif

+ 152 - 0
headers/zivuos/vector_helpers.h

@@ -0,0 +1,152 @@
+#ifndef CX_ZIVUOS_VECTOR_HELPERS_H_INCLUDED
+#define CX_ZIVUOS_VECTOR_HELPERS_H_INCLUDED
+
+#include <stdint.h>
+#include <stddef.h>
+#include <stdbool.h>
+
+#include "models.h"
+#include "vector.h"
+
+static inline uintptr_t zv_vector_get_unumber(
+    zv_vector_t *self, 
+    size_t count
+) {
+    return zv_vector_get(self, count).unumber;
+}
+
+static inline intptr_t zv_vector_get_number(
+    zv_vector_t *self,
+    size_t count
+) {
+    return zv_vector_get(self, count).number;
+}
+
+static inline void * zv_vector_get_pointer(
+    zv_vector_t *self,
+    size_t count
+) {
+    return zv_vector_get(self, count).pointer;
+}
+
+static inline char * zv_vector_get_cstring(
+    zv_vector_t *self,
+    size_t count
+) {
+    return zv_vector_get(self, count).cstring;
+}
+
+static inline size_t zv_vector_push_unumber(
+    zv_vector_t *self, 
+    uintptr_t unumber
+) {
+    zv_universal_t target;
+    target.unumber = unumber;
+
+    return zv_vector_push(self, target);
+}
+
+static inline size_t zv_vector_push_number(
+    zv_vector_t *self, 
+    intptr_t number
+) {
+    zv_universal_t target;
+    target.number = number;
+
+    return zv_vector_push(self, target);
+}
+
+static inline size_t zv_vector_push_pointer(
+    zv_vector_t *self, 
+    void *pointer
+) {
+    zv_universal_t target;
+    target.pointer = pointer;
+
+    return zv_vector_push(self, target);
+}
+
+static inline size_t zv_vector_push_cstring(
+    zv_vector_t *self, 
+    char *cstring
+) {
+    zv_universal_t target;
+    target.cstring = cstring;
+
+    return zv_vector_push(self, target);
+}
+
+static inline uintptr_t zv_vector_pop_unumber(
+    zv_vector_t *self, 
+    size_t count
+) {
+    return zv_vector_pop(self, count).unumber;
+}
+
+static inline intptr_t zv_vector_pop_number(
+    zv_vector_t *self, 
+    size_t count
+) {
+    return zv_vector_pop(self, count).number;
+}
+
+static inline void * zv_vector_pop_pointer(
+    zv_vector_t *self, 
+    size_t count
+) {
+    return zv_vector_pop(self, count).pointer;
+}
+
+static inline char * zv_vector_pop_cstring(
+    zv_vector_t *self, 
+    size_t count
+) {
+    return zv_vector_pop(self, count).cstring;
+}
+
+static inline bool zv_vector_insert_unumber(
+    zv_vector_t *self,
+    uintptr_t target,
+    size_t count
+) {
+    zv_universal_t translator;
+    translator.unumber = target;
+
+    return zv_vector_insert(self, translator, count);
+}
+
+static inline bool zv_vector_insert_number(
+    zv_vector_t *self,
+    intptr_t target,
+    size_t count
+) {
+    zv_universal_t translator;
+    translator.number = target;
+
+    return zv_vector_insert(self, translator, count);
+}
+
+static inline bool zv_vector_insert_pointer(
+    zv_vector_t *self,
+    void *target,
+    size_t count
+) {
+    zv_universal_t translator;
+    translator.pointer = target;
+
+    return zv_vector_insert(self, translator, count);
+}
+
+static inline bool zv_vector_insert_cstring(
+    zv_vector_t *self,
+    char *target,
+    size_t count
+) {
+    zv_universal_t translator;
+    translator.cstring = target;
+
+    return zv_vector_insert(self, translator, count);
+}
+
+#endif
+

+ 31 - 0
sources/alloc.c

@@ -0,0 +1,31 @@
+#include <stdint.h>
+#include <stddef.h>
+#include <stdbool.h>
+
+#include "alloc.h"
+
+#ifdef ZV_ALLOC_USE_STDLIB
+#include <stdlib.h>
+#include <malloc.h>
+#endif
+
+
+void * zv_alloc(size_t count) {
+    #ifdef ZV_ALLOC_USE_STDLIB
+    return malloc(count);   
+    #endif
+}
+
+void * zv_alloc_zero(size_t count) {
+    #ifdef ZV_ALLOC_USE_STDLIB
+    return calloc(count, 0);
+    #endif
+}
+
+void zv_free(void *target) {
+    #ifdef ZV_ALLOC_USE_STDLIB
+    free(target);
+    #endif
+}
+
+

+ 9 - 0
sources/kernel.c

@@ -47,6 +47,15 @@ zv_pid_t zv_kernel_add_process(
     return ZV_ERROR_PID;
 }
 
+bool zv_kernel_set_scheduler(zv_kernel_t *self, zv_scheduler_mode_t target) {
+#ifdef ZV_KERNEL_SCHEDULER_SINGLE_MODE
+    return false;
+#else
+    self->mode = target;
+    return true;
+#endif
+}
+
 void __zv_kernel_clean_balance(zv_kernel_t *self) {
     for (zv_pid_t count = 0; count < self->processes_count; ++count) {
         zv_process_t *current = self->processes + count;

+ 6 - 5
sources/process.c

@@ -1,16 +1,17 @@
 #include "process.h"
 #include "result.h"
 
-zv_result_t zv_process_change_worker(zv_process_t *self, zv_worker_t target) {
+zv_result_t zv_process_set_worker(zv_process_t *self, zv_worker_t target) {
     self->worker = target;
     return ZV_SUCCESS;
 }
 
-zv_result_t zv_process_change_param(
-    zv_process_t *self, 
-    zv_universal_t target
-) {
+zv_result_t zv_process_set_param(zv_process_t *self, zv_universal_t target) {
     self->param = target;
     return ZV_SUCCESS;
 }
 
+zv_result_t zv_process_set_state(zv_process_t *self, zv_priority_t target) {
+    self->priority = target;
+    return ZV_SUCCESS;
+}

+ 89 - 0
sources/vector.c

@@ -0,0 +1,89 @@
+#include <stdint.h>
+#include <stddef.h>
+#include <stdbool.h>
+
+#include "vector.h"
+#include "alloc.h"
+
+zv_vector_t * zv_vector_create() {
+    zv_vector_t *result = (zv_vector_t *) zv_alloc(sizeof(zv_vector_t));
+    
+    if (result == NULL) {
+        return NULL;
+    }
+
+    result->lenght = 0;
+    result->first = NULL;
+    result->last = NULL;
+
+    return result;    
+}
+
+static inline zv_vector_container_t * __zv_vector_count_right(
+    zv_vector_t *self,
+    size_t count
+) {
+    zv_vector_container_t *current = self->last;
+    count = self->lenght - count;
+    
+    while (count-- > 0) {
+        current = current->previous;
+
+        if (current == NULL) {
+            return NULL;
+        }
+    }
+
+    return current;
+}
+
+static inline zv_vector_container_t * __zv_vector_count_lefr(
+    zv_vector_t *self,
+    size_t count
+) {
+    zv_vector_container_t *current = self->first;
+
+    while (count-- > 0) {
+        current = current->next;
+
+        if (current == NULL) {
+            return NULL;
+        }
+    }
+
+    return current;
+}
+
+static zv_vector_container_t * __zv_vector_get_container(
+    zv_vector_t *self, 
+    size_t count
+) {
+    if (self->lenght <= count) {
+        return NULL;
+    }
+
+    if (self->lenght / 2 > count) {
+        return __zv_vector_count_right(self, count);
+    } 
+
+    return __zv_vector_count_left(self, count);
+}
+
+zv_universal_t zv_vector_get(zv_vector_t *self, size_t count) {
+    zv_vector_container_t *current = __zv_vector_get_container(self, count);
+    
+    if (current == NULL) {
+        return NULL;
+    }
+
+    return current->content;
+}
+
+size_t zv_vector_push(zv_vector_t *, zv_universal_t);
+size_t zv_vector_count(zv_vector_t *);
+zv_universal_t zv_vector_pop(zv_vector_t *, size_t);
+bool zv_vector_insert(zv_vector_t *, zv_universal_t, size_t);
+void zv_vector_remove(zv_vector_t *);
+zv_universal_t * zv_vector_to_array(zv_vector_t *);
+
+

+ 27 - 0
x

@@ -0,0 +1,27 @@
+/home/taiga/cx-zivuos/build-generic/../sources/alloc.c: In function ‘zv_alloc’:
+/home/taiga/cx-zivuos/build-generic/../sources/alloc.c:13:12: error: implicit declaration of function ‘malloc’ [-Wimplicit-function-declaration]
+   13 |     return malloc(count);
+      |            ^~~~~~
+/home/taiga/cx-zivuos/build-generic/../sources/alloc.c:10:1: note: include ‘<stdlib.h>’ or provide a declaration of ‘malloc’
+    9 | #include "alloc.h"
+  +++ |+#include <stdlib.h>
+   10 | 
+/home/taiga/cx-zivuos/build-generic/../sources/alloc.c:13:12: warning: incompatible implicit declaration of built-in function ‘malloc’ [-Wbuiltin-declaration-mismatch]
+   13 |     return malloc(count);
+      |            ^~~~~~
+/home/taiga/cx-zivuos/build-generic/../sources/alloc.c:13:12: note: include ‘<stdlib.h>’ or provide a declaration of ‘malloc’
+/home/taiga/cx-zivuos/build-generic/../sources/alloc.c: In function ‘zv_alloc_zero’:
+/home/taiga/cx-zivuos/build-generic/../sources/alloc.c:19:12: error: implicit declaration of function ‘calloc’ [-Wimplicit-function-declaration]
+   19 |     return calloc(count);
+      |            ^~~~~~
+/home/taiga/cx-zivuos/build-generic/../sources/alloc.c:19:12: note: include ‘<stdlib.h>’ or provide a declaration of ‘calloc’
+/home/taiga/cx-zivuos/build-generic/../sources/alloc.c:19:12: warning: incompatible implicit declaration of built-in function ‘calloc’ [-Wbuiltin-declaration-mismatch]
+/home/taiga/cx-zivuos/build-generic/../sources/alloc.c:19:12: note: include ‘<stdlib.h>’ or provide a declaration of ‘calloc’
+/home/taiga/cx-zivuos/build-generic/../sources/alloc.c:19:12: error: too few arguments to function ‘calloc’; expected 2, have 1
+/home/taiga/cx-zivuos/build-generic/../sources/alloc.c: In function ‘zv_free’:
+/home/taiga/cx-zivuos/build-generic/../sources/alloc.c:25:5: error: implicit declaration of function ‘free’ [-Wimplicit-function-declaration]
+   25 |     free(target);
+      |     ^~~~
+/home/taiga/cx-zivuos/build-generic/../sources/alloc.c:25:5: note: include ‘<stdlib.h>’ or provide a declaration of ‘free’
+/home/taiga/cx-zivuos/build-generic/../sources/alloc.c:25:5: warning: incompatible implicit declaration of built-in function ‘free’ [-Wbuiltin-declaration-mismatch]
+/home/taiga/cx-zivuos/build-generic/../sources/alloc.c:25:5: note: include ‘<stdlib.h>’ or provide a declaration of ‘free’