You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@mynewt.apache.org by we...@apache.org on 2015/12/04 08:24:15 UTC

[1/2] incubator-mynewt-larva git commit: If a task was waiting on a semaphore with a timeout and the timeout occurred, the task was not removed from the list of tasks waiting on the semaphore. Modify semaphore, mutex and task code to use the same pointer

Repository: incubator-mynewt-larva
Updated Branches:
  refs/heads/master f945610a8 -> 61e8c4733


If a task was waiting on a semaphore with a timeout and the timeout occurred, the task was not removed from the list of tasks waiting on the semaphore. Modify semaphore, mutex and task code to use the same pointer (t_obj) in the task structure when a task is waiting on an object. Add mutex wait flag (set when a task is waiting on a mutex) and add simple tests


Project: http://git-wip-us.apache.org/repos/asf/incubator-mynewt-larva/repo
Commit: http://git-wip-us.apache.org/repos/asf/incubator-mynewt-larva/commit/61e8c473
Tree: http://git-wip-us.apache.org/repos/asf/incubator-mynewt-larva/tree/61e8c473
Diff: http://git-wip-us.apache.org/repos/asf/incubator-mynewt-larva/diff/61e8c473

Branch: refs/heads/master
Commit: 61e8c4733ecd00c2037030284d0eb84f401242a5
Parents: 3b25ce3
Author: wes3 <wi...@micosa.io>
Authored: Thu Dec 3 23:23:41 2015 -0800
Committer: wes3 <wi...@micosa.io>
Committed: Thu Dec 3 23:23:51 2015 -0800

----------------------------------------------------------------------
 libs/os/include/os/os_mutex.h |  2 +-
 libs/os/include/os/os_sem.h   |  2 +-
 libs/os/include/os/os_task.h  | 15 ++++++++++++++-
 libs/os/src/os_mutex.c        | 19 ++++++++-----------
 libs/os/src/os_sched.c        | 13 ++++++++-----
 libs/os/src/os_sem.c          | 11 +++--------
 libs/os/src/test/mutex_test.c |  9 +++++++++
 libs/os/src/test/sem_test.c   |  2 +-
 8 files changed, 45 insertions(+), 28 deletions(-)
----------------------------------------------------------------------


http://git-wip-us.apache.org/repos/asf/incubator-mynewt-larva/blob/61e8c473/libs/os/include/os/os_mutex.h
----------------------------------------------------------------------
diff --git a/libs/os/include/os/os_mutex.h b/libs/os/include/os/os_mutex.h
index 716ba60..a16c370 100644
--- a/libs/os/include/os/os_mutex.h
+++ b/libs/os/include/os/os_mutex.h
@@ -22,11 +22,11 @@
 
 struct os_mutex
 {
+    SLIST_HEAD(, os_task) mu_head;  /* chain of waiting tasks */
     uint8_t     _pad;
     uint8_t     mu_prio;            /* owner's default priority*/
     uint16_t    mu_level;           /* call nesting level */
     struct os_task *mu_owner;       /* owners task */
-    SLIST_HEAD(, os_task) mu_head;  /* chain of waiting tasks */
 };
 
 /* 

http://git-wip-us.apache.org/repos/asf/incubator-mynewt-larva/blob/61e8c473/libs/os/include/os/os_sem.h
----------------------------------------------------------------------
diff --git a/libs/os/include/os/os_sem.h b/libs/os/include/os/os_sem.h
index 73e84ee..b0eb8bf 100644
--- a/libs/os/include/os/os_sem.h
+++ b/libs/os/include/os/os_sem.h
@@ -21,9 +21,9 @@
 
 struct os_sem
 {
+    SLIST_HEAD(, os_task) sem_head;     /* chain of waiting tasks */
     uint16_t    _pad;
     uint16_t    sem_tokens;             /* # of tokens */
-    SLIST_HEAD(, os_task) sem_head; /* chain of waiting tasks */
 };
 
 /* 

http://git-wip-us.apache.org/repos/asf/incubator-mynewt-larva/blob/61e8c473/libs/os/include/os/os_task.h
----------------------------------------------------------------------
diff --git a/libs/os/include/os/os_task.h b/libs/os/include/os/os_task.h
index 3f75432..ae44a73 100644
--- a/libs/os/include/os/os_task.h
+++ b/libs/os/include/os/os_task.h
@@ -29,6 +29,18 @@
 #define OS_TASK_NAME_SIZE (36) 
 #endif 
 
+/* 
+ * Generic "object" structure. All objects that a task can wait on must
+ * have a SLIST_HEAD(, os_task) head_name as the first element in the object 
+ * structure. The element 'head_name' can be any name. See os_mutex.h or
+ * os_sem.h for an example.
+ */
+struct os_task_obj
+{
+    SLIST_HEAD(, os_task) obj_head;     /* chain of waiting tasks */
+};
+
+/* Task states */
 typedef enum os_task_state {
     OS_TASK_READY = 1, 
     OS_TASK_SLEEP = 2
@@ -37,6 +49,7 @@ typedef enum os_task_state {
 /* Task flags */
 #define OS_TASK_FLAG_NO_TIMEOUT     (0x0001U)
 #define OS_TASK_FLAG_SEM_WAIT       (0x0002U)
+#define OS_TASK_FLAG_MUTEX_WAIT     (0x0004U)
 
 typedef void (*os_task_func_t)(void *);
 
@@ -54,7 +67,7 @@ struct os_task {
     os_task_func_t t_func;
     void *t_arg;
 
-    struct os_mutex *t_mutex;
+    void *t_obj;
 
     struct os_sanity_check t_sanity_check; 
 

http://git-wip-us.apache.org/repos/asf/incubator-mynewt-larva/blob/61e8c473/libs/os/src/os_mutex.c
----------------------------------------------------------------------
diff --git a/libs/os/src/os_mutex.c b/libs/os/src/os_mutex.c
index 3ad3151..0965be8 100644
--- a/libs/os/src/os_mutex.c
+++ b/libs/os/src/os_mutex.c
@@ -98,11 +98,7 @@ os_mutex_release(struct os_mutex *mu)
     rdy = SLIST_FIRST(&mu->mu_head);
     if (rdy) {
         /* There is one waiting. Wake it up */
-        assert(rdy->t_mutex);
-        rdy->t_mutex = NULL;
-
-        SLIST_REMOVE_HEAD(&mu->mu_head, t_obj_list);
-        SLIST_NEXT(rdy, t_obj_list) = NULL;
+        assert(rdy->t_obj);
         os_sched_wakeup(rdy);
 
         /* Set mutex internals */
@@ -214,13 +210,17 @@ os_mutex_pend(struct os_mutex *mu, uint32_t timeout)
     }
 
     /* Set mutex pointer in task */
-    current->t_mutex = mu;
+    current->t_obj = mu;
+    current->t_flags |= OS_TASK_FLAG_MUTEX_WAIT;
     os_sched_sleep(current, timeout);
-
     OS_EXIT_CRITICAL(sr);
 
     os_sched(NULL, 0);
 
+    OS_ENTER_CRITICAL(sr);
+    current->t_flags &= ~OS_TASK_FLAG_MUTEX_WAIT;
+    OS_EXIT_CRITICAL(sr);
+
     /* If we are owner we did not time out. */
     if (mu->mu_owner == current) {
         rc = OS_OK; 
@@ -276,10 +276,7 @@ os_mutex_delete(struct os_mutex *mu)
     /* Now, go through all the tasks waiting on the mutex */
     while (!SLIST_EMPTY(&mu->mu_head)) {
         rdy = SLIST_FIRST(&mu->mu_head);
-        assert(rdy->t_mutex);
-        rdy->t_mutex = NULL;
-        SLIST_REMOVE_HEAD(&mu->mu_head, t_obj_list);
-        SLIST_NEXT(rdy, t_obj_list) = NULL;
+        assert(rdy->t_obj);
         os_sched_wakeup(rdy);
     }
 

http://git-wip-us.apache.org/repos/asf/incubator-mynewt-larva/blob/61e8c473/libs/os/src/os_sched.c
----------------------------------------------------------------------
diff --git a/libs/os/src/os_sched.c b/libs/os/src/os_sched.c
index f287c6b..f1c03c6 100644
--- a/libs/os/src/os_sched.c
+++ b/libs/os/src/os_sched.c
@@ -243,14 +243,17 @@ os_sched_sleep(struct os_task *t, os_time_t nticks)
 int 
 os_sched_wakeup(struct os_task *t) 
 {
+    struct os_task_obj *os_obj;
+
     assert(t->t_state == OS_TASK_SLEEP);
 
-    /* Remove self from mutex list if waiting on one */
-    if (t->t_mutex) {
-        assert(!SLIST_EMPTY(&t->t_mutex->mu_head));
-        SLIST_REMOVE(&t->t_mutex->mu_head, t, os_task, t_obj_list);
+    /* Remove self from object list if waiting on one */
+    if (t->t_obj) {
+        os_obj = (struct os_task_obj *)t->t_obj;
+        assert(!SLIST_EMPTY(&os_obj->obj_head));
+        SLIST_REMOVE(&os_obj->obj_head, t, os_task, t_obj_list);
         SLIST_NEXT(t, t_obj_list) = NULL;
-        t->t_mutex = NULL; 
+        t->t_obj = NULL; 
     }
 
     /* Remove task from sleep list */

http://git-wip-us.apache.org/repos/asf/incubator-mynewt-larva/blob/61e8c473/libs/os/src/os_sem.c
----------------------------------------------------------------------
diff --git a/libs/os/src/os_sem.c b/libs/os/src/os_sem.c
index d3b395c..84464d3 100644
--- a/libs/os/src/os_sem.c
+++ b/libs/os/src/os_sem.c
@@ -86,12 +86,8 @@ os_sem_release(struct os_sem *sem)
     /* Check if tasks are waiting for the semaphore */
     rdy = SLIST_FIRST(&sem->sem_head);
     if (rdy) {
-        /* Clear flag that we are waiting on the semaphore */
+        /* Clear flag that we are waiting on the semaphore; wake up task */
         rdy->t_flags &= ~OS_TASK_FLAG_SEM_WAIT;
-
-        /* There is one waiting. Wake it up */
-        SLIST_REMOVE_HEAD(&sem->sem_head, t_obj_list);
-        SLIST_NEXT(rdy, t_obj_list) = NULL;
         os_sched_wakeup(rdy);
 
         /* Schedule if waiting task higher priority */
@@ -169,6 +165,7 @@ os_sem_pend(struct os_sem *sem, uint32_t timeout)
         rc = OS_OK;
 
         /* Link current task to tasks waiting for semaphore */
+        current->t_obj = sem; 
         current->t_flags |= OS_TASK_FLAG_SEM_WAIT;
         last = NULL;
         if (!SLIST_EMPTY(&sem->sem_head)) {
@@ -258,9 +255,7 @@ os_sem_delete(struct os_sem *sem)
 
         /* Now, go through all the tasks waiting on the semaphore */
         while (rdy != NULL) {
-            SLIST_REMOVE_HEAD(&sem->sem_head, t_obj_list);
-            SLIST_NEXT(rdy, t_obj_list) = NULL;
-            os_sched_wakeup(rdy);
+            os_sched_wakeup(rdy); 
             rdy = SLIST_FIRST(&sem->sem_head);
         }
     }

http://git-wip-us.apache.org/repos/asf/incubator-mynewt-larva/blob/61e8c473/libs/os/src/test/mutex_test.c
----------------------------------------------------------------------
diff --git a/libs/os/src/test/mutex_test.c b/libs/os/src/test/mutex_test.c
index a861dbb..7d9a08c 100644
--- a/libs/os/src/test/mutex_test.c
+++ b/libs/os/src/test/mutex_test.c
@@ -178,6 +178,14 @@ mutex_test2_task14_handler(void *arg)
         g_task14_val = 1;
         os_time_delay(100);
 
+        /* 
+         * Task17 should have its mutex wait flag set; at least the first time
+         * through!
+         */
+        if (iters == 0) {
+            TEST_ASSERT(task17.t_flags & OS_TASK_FLAG_MUTEX_WAIT);
+        }
+
         if (g_mutex_test == 4) {
             os_mutex_delete(&g_mutex1);
             os_time_delay(150);
@@ -303,6 +311,7 @@ task17_handler(void *arg)
             err = os_mutex_pend(&g_mutex1, 10);
         } else {
             err = os_mutex_pend(&g_mutex1, 10000);
+            TEST_ASSERT((t->t_flags & OS_TASK_FLAG_MUTEX_WAIT) == 0);
         }
 
         if (g_mutex_test == 4 || g_mutex_test == 5) {

http://git-wip-us.apache.org/repos/asf/incubator-mynewt-larva/blob/61e8c473/libs/os/src/test/sem_test.c
----------------------------------------------------------------------
diff --git a/libs/os/src/test/sem_test.c b/libs/os/src/test/sem_test.c
index 75b2e40..fbaf82b 100644
--- a/libs/os/src/test/sem_test.c
+++ b/libs/os/src/test/sem_test.c
@@ -95,7 +95,7 @@ sem_test_pend_release_loop(int delay, int timeout, int itvl)
 
     while (1) {
         err = os_sem_pend(&g_sem1, timeout);
-        TEST_ASSERT(err == OS_OK);
+        TEST_ASSERT((err == OS_OK) || (err == OS_TIMEOUT));
 
         err = os_sem_release(&g_sem1);
         TEST_ASSERT(err == OS_OK);


[2/2] incubator-mynewt-larva git commit: Need to add stdint.h for some targets

Posted by we...@apache.org.
Need to add stdint.h for some targets


Project: http://git-wip-us.apache.org/repos/asf/incubator-mynewt-larva/repo
Commit: http://git-wip-us.apache.org/repos/asf/incubator-mynewt-larva/commit/3b25ce3d
Tree: http://git-wip-us.apache.org/repos/asf/incubator-mynewt-larva/tree/3b25ce3d
Diff: http://git-wip-us.apache.org/repos/asf/incubator-mynewt-larva/diff/3b25ce3d

Branch: refs/heads/master
Commit: 3b25ce3d3e0c55fc24c1c0925e1fdbef70f8e3e5
Parents: f945610
Author: wes3 <wi...@micosa.io>
Authored: Thu Dec 3 23:19:56 2015 -0800
Committer: wes3 <wi...@micosa.io>
Committed: Thu Dec 3 23:23:51 2015 -0800

----------------------------------------------------------------------
 libs/util/include/util/base64.h | 2 ++
 1 file changed, 2 insertions(+)
----------------------------------------------------------------------


http://git-wip-us.apache.org/repos/asf/incubator-mynewt-larva/blob/3b25ce3d/libs/util/include/util/base64.h
----------------------------------------------------------------------
diff --git a/libs/util/include/util/base64.h b/libs/util/include/util/base64.h
index 8d978c5..fff40fd 100644
--- a/libs/util/include/util/base64.h
+++ b/libs/util/include/util/base64.h
@@ -16,6 +16,8 @@
 #ifndef __UTIL_BASE64_H 
 #define __UTIL_BASE64_H 
 
+#include <stdint.h>
+
 int base64_encode(const void *, int, char *, uint8_t);
 int base64_decode(const char *, void *buf);