From 503a0bbadafe320d2d9670e4ede9589bb0abef04 Mon Sep 17 00:00:00 2001
From: Kubat <mael.martin31@gmail.com>
Date: Wed, 29 Apr 2020 19:22:03 +0200
Subject: [PATCH] Running the mthread_main, that thing is a glutton

---
 inc/mthread/mthread.h | 1 +
 src/main/server.c     | 6 +++---
 src/mthread/mthread.c | 7 +++----
 3 files changed, 7 insertions(+), 7 deletions(-)

diff --git a/inc/mthread/mthread.h b/inc/mthread/mthread.h
index e3184b88..a370405b 100644
--- a/inc/mthread/mthread.h
+++ b/inc/mthread/mthread.h
@@ -106,3 +106,4 @@ void mthread_yield();
 /* Initialize mthread. */
 
 void mthread_init();
+void *mthread_main(void *arg);
diff --git a/src/main/server.c b/src/main/server.c
index 3c12393a..434784e2 100644
--- a/src/main/server.c
+++ b/src/main/server.c
@@ -11,6 +11,7 @@
 #include <string.h>
 #include <strings.h>
 #include <pwd.h>
+#include <pthread.h>
 
 /* Prints the help of the program */
 static void
@@ -37,10 +38,9 @@ print_help(void)
 int
 main(int argc, char *argv[])
 {
-    /* Variable initialisation */
     struct passwd *pw = getpwuid(getuid());
+    pthread_t th;
 
-    /* Argument handleing */
     if (argc <= 1)
         goto normal_launch;
     else if (strcasecmp(argv[1], "--help") == 0 ||
@@ -58,6 +58,6 @@ main(int argc, char *argv[])
 normal_launch:
     LOG_INFO("Lektor launched by user %s (shell: %s, home: %s)", pw->pw_name, pw->pw_shell, pw->pw_dir);
     mthread_init();
-
+    pthread_create(&th, NULL, mthread_main, NULL);
     return lkt_listen();
 }
diff --git a/src/mthread/mthread.c b/src/mthread/mthread.c
index 47fff88c..07d6918f 100644
--- a/src/mthread/mthread.c
+++ b/src/mthread/mthread.c
@@ -133,7 +133,6 @@ __mthread_yield(mthread_virtual_processor_t *vp)
     struct mthread_s *next    = mthread_remove_first(&(vp->ready_list));
 
     if (vp->resched != NULL) {
-        LOG_INFO_SCT("SCHEDULER", "Insert %p in ready list of %d", (void *) vp->resched, vp->rank);
         mthread_insert_last((struct mthread_s *)vp->resched, &(vp->ready_list));
         vp->resched = NULL;
     }
@@ -151,9 +150,9 @@ __mthread_yield(mthread_virtual_processor_t *vp)
             next = vp->idle;
     }
 
-    if (next != NULL) { /* always true at this point - except for idle thread */
+    /* always true at this point - except for idle thread */
+    if (next != NULL) {
         if (vp->current != next) {
-            LOG_INFO_SCT("SCHEDULER", "Swap from %p to %p", (void *) current, (void *) next);
             vp->current = next;
             mthread_mctx_swap(current, next);
         }
@@ -213,7 +212,7 @@ mthread_init_vp(mthread_virtual_processor_t *vp, struct mthread_s *idle,
     vp->p       = NULL;
 }
 
-static inline void *
+void *
 mthread_main(void *arg)
 {
     (void)arg;
-- 
GitLab