You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@mynewt.apache.org by GitBox <gi...@apache.org> on 2017/12/20 02:14:58 UTC

[GitHub] wes3 closed pull request #709: MYNEWT-879: OS scheduler issues with TAILQ_INSERT_TAIL

wes3 closed pull request #709: MYNEWT-879: OS scheduler issues with TAILQ_INSERT_TAIL
URL: https://github.com/apache/mynewt-core/pull/709
 
 
   

This is a PR merged from a forked repository.
As GitHub hides the original diff on merge, it is displayed below for
the sake of provenance:

As this is a foreign pull request (from a fork), the diff is supplied
below (as it won't show otherwise due to GitHub magic):

diff --git a/kernel/os/src/os_sched.c b/kernel/os/src/os_sched.c
index cb0b02063..50a64eb96 100644
--- a/kernel/os/src/os_sched.c
+++ b/kernel/os/src/os_sched.c
@@ -64,15 +64,21 @@ os_sched_insert(struct os_task *t)
 
     entry = NULL;
     OS_ENTER_CRITICAL(sr);
-    TAILQ_FOREACH(entry, &g_os_run_list, t_os_list) {
-        if (t->t_prio < entry->t_prio) {
-            break;
-        }
-    }
-    if (entry) {
-        TAILQ_INSERT_BEFORE(entry, (struct os_task *) t, t_os_list);
+
+    /* If run list empty, add to front */
+    if (TAILQ_EMPTY(&g_os_run_list)) {
+        TAILQ_INSERT_HEAD(&g_os_run_list, t, t_os_list);
     } else {
-        TAILQ_INSERT_TAIL(&g_os_run_list, (struct os_task *) t, t_os_list);
+        TAILQ_FOREACH(entry, &g_os_run_list, t_os_list) {
+            if (t->t_prio < entry->t_prio) {
+                break;
+            }
+        }
+        if (entry) {
+            TAILQ_INSERT_BEFORE(entry, (struct os_task *) t, t_os_list);
+        } else {
+            TAILQ_INSERT_TAIL(&g_os_run_list, (struct os_task *) t, t_os_list);
+        }
     }
     OS_EXIT_CRITICAL(sr);
 
@@ -177,8 +183,18 @@ os_sched_sleep(struct os_task *t, os_time_t nticks)
     TAILQ_REMOVE(&g_os_run_list, t, t_os_list);
     t->t_state = OS_TASK_SLEEP;
     t->t_next_wakeup = os_time_get() + nticks;
+
     if (nticks == OS_TIMEOUT_NEVER) {
         t->t_flags |= OS_TASK_FLAG_NO_TIMEOUT;
+    }
+
+    /* If sleep list empty, add to front */
+    if (TAILQ_EMPTY(&g_os_sleep_list)) {
+        TAILQ_INSERT_HEAD(&g_os_sleep_list, t, t_os_list);
+        goto exit_sched_sleep;
+    }
+
+    if (nticks == OS_TIMEOUT_NEVER) {
         TAILQ_INSERT_TAIL(&g_os_sleep_list, t, t_os_list);
     } else {
         TAILQ_FOREACH(entry, &g_os_sleep_list, t_os_list) {
@@ -194,6 +210,7 @@ os_sched_sleep(struct os_task *t, os_time_t nticks)
         }
     }
 
+exit_sched_sleep:
     os_trace_task_stop_ready(t->t_taskid, OS_TASK_SLEEP);
     return (0);
 }


 

----------------------------------------------------------------
This is an automated message from the Apache Git Service.
To respond to the message, please log on GitHub and use the
URL above to go to the specific comment.
 
For queries about this service, please contact Infrastructure at:
users@infra.apache.org


With regards,
Apache Git Services