dedicated kthread interface and enablement of lrud auto-recycler
[lunaix-os.git] / lunaix-os / kernel / lunad.c
index b808022ab1f8f4ee10d1c34587bbd90a050b0a45..25ce7d21d0014c14a7479195216ac86d7b0839a5 100644 (file)
@@ -10,6 +10,7 @@
 #include <lunaix/sched.h>
 #include <lunaix/kpreempt.h>
 #include <lunaix/kcmd.h>
+#include <lunaix/kthread.h>
 
 #include <klibc/string.h>
 
@@ -84,6 +85,17 @@ lunad_do_usr() {
     }
 }
 
+static void
+__thread_cleaner()
+{
+    while (true)
+    {
+        cleanup_detached_threads();
+        kthread_sleep(30);
+    }
+}
+
+
 /**
  * @brief LunaixOS的内核进程,该进程永远为可执行。
  *
@@ -95,23 +107,11 @@ lunad_do_usr() {
 void
 lunad_main()
 {
-    spawn_kthread((ptr_t)init_platform);
-
-    /*
-        NOTE Kernel preemption after this point.
+    kthread_spawn((ptr_t)init_platform);
+    kthread_spawn((ptr_t)__thread_cleaner);
 
-        More specifically, it is not a real kernel preemption (as in preemption
-        happened at any point of kernel, except those marked explicitly).
-        In Lunaix, things are designed in an non-preemptive fashion, we implement 
-        kernel preemption the other way around: only selected kernel functions which,
-        of course, with great care of preemptive assumption, will goes into kernel 
-        thread (which is preemptive!)
-    */
-
-    set_preemption();
     while (1)
     {
-        cleanup_detached_threads();
         yield_current();
     }
 }