You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@mynewt.apache.org by cc...@apache.org on 2017/02/09 03:00:26 UTC

[3/3] incubator-mynewt-core git commit: MYNEWT-534 os - Move start ev when evq reassigned.

MYNEWT-534 os - Move start ev when evq reassigned.

If an application wants a package to use an event queue other than the
main event queue, it calls the package-specific evq-set function.  When
this happens, the package's start event (if any) needs to be moved from
the previous queue to the new one.


Project: http://git-wip-us.apache.org/repos/asf/incubator-mynewt-core/repo
Commit: http://git-wip-us.apache.org/repos/asf/incubator-mynewt-core/commit/64c288f6
Tree: http://git-wip-us.apache.org/repos/asf/incubator-mynewt-core/tree/64c288f6
Diff: http://git-wip-us.apache.org/repos/asf/incubator-mynewt-core/diff/64c288f6

Branch: refs/heads/develop
Commit: 64c288f6a4f4ce188305f0d66c719a1467a39948
Parents: 4719b3f
Author: Christopher Collins <cc...@apache.org>
Authored: Wed Feb 8 18:49:46 2017 -0800
Committer: Christopher Collins <cc...@apache.org>
Committed: Wed Feb 8 19:00:04 2017 -0800

----------------------------------------------------------------------
 kernel/os/include/os/os_eventq.h |  2 --
 kernel/os/src/os.c               |  2 +-
 kernel/os/src/os_eventq.c        | 47 ++++++++++++++++++++---------------
 3 files changed, 28 insertions(+), 23 deletions(-)
----------------------------------------------------------------------


http://git-wip-us.apache.org/repos/asf/incubator-mynewt-core/blob/64c288f6/kernel/os/include/os/os_eventq.h
----------------------------------------------------------------------
diff --git a/kernel/os/include/os/os_eventq.h b/kernel/os/include/os/os_eventq.h
index 092e724..2ae779c 100644
--- a/kernel/os/include/os/os_eventq.h
+++ b/kernel/os/include/os/os_eventq.h
@@ -56,8 +56,6 @@ void os_eventq_remove(struct os_eventq *, struct os_event *);
 struct os_eventq *os_eventq_dflt_get(void);
 void os_eventq_designate(struct os_eventq **dst, struct os_eventq *val,
                          struct os_event *start_ev);
-void os_eventq_ensure(struct os_eventq **evq, struct os_event *start_ev);
-
 #ifdef __cplusplus
 }
 #endif

http://git-wip-us.apache.org/repos/asf/incubator-mynewt-core/blob/64c288f6/kernel/os/src/os.c
----------------------------------------------------------------------
diff --git a/kernel/os/src/os.c b/kernel/os/src/os.c
index 754dcea..cbf8b62 100644
--- a/kernel/os/src/os.c
+++ b/kernel/os/src/os.c
@@ -132,7 +132,6 @@ os_main(void *arg)
 {
     int (*fn)(int argc, char **argv) = arg;
 
-    os_eventq_init(os_eventq_dflt_get());
 #if !MYNEWT_VAL(SELFTEST)
     fn(0, NULL);
 #else
@@ -175,6 +174,7 @@ os_init(int (*main_fn)(int argc, char **arg))
 
     TAILQ_INIT(&g_callout_list);
     STAILQ_INIT(&g_os_task_list);
+    os_eventq_init(os_eventq_dflt_get());
 
     /* Initialize device list. */
     os_dev_reset();

http://git-wip-us.apache.org/repos/asf/incubator-mynewt-core/blob/64c288f6/kernel/os/src/os_eventq.c
----------------------------------------------------------------------
diff --git a/kernel/os/src/os_eventq.c b/kernel/os/src/os_eventq.c
index d5be9ae..626d560 100644
--- a/kernel/os/src/os_eventq.c
+++ b/kernel/os/src/os_eventq.c
@@ -289,32 +289,39 @@ os_eventq_dflt_get(void)
     return &os_eventq_main;
 }
 
+/**
+ * Reassigns an event queue pointer to the specified value.  This function is
+ * used for configuring a package to use a particular event queue.  A package's
+ * event queue can generally be reassigned repeatedly.  If the package has a
+ * startup event, the event is moved from the current queue (if any) to the
+ * specified queue.
+ *
+ * @param cur_evq               Points to the eventq pointer to reassign.
+ *                                  *cur_evq should be NULL if the package's
+ *                                  eventq has not been assigned yet.
+ * @param new_evq               The eventq that the package should be
+ *                                  associated with.
+ * @param start_ev              The package's startup event, if any.  If this
+ *                                  is non-NULL, the event gets removed from
+ *                                  the current queue (if set), and enqueued to
+ *                                  the new eventq.
+ */
 void
-os_eventq_designate(struct os_eventq **dst, struct os_eventq *val,
+os_eventq_designate(struct os_eventq **cur_evq,
+                    struct os_eventq *new_evq,
                     struct os_event *start_ev)
 {
-    *dst = val;
-    if (start_ev != NULL) {
-        os_eventq_put(*dst, start_ev);
-    }
-}
+    struct os_eventq *prev_evq;
 
-void
-os_eventq_ensure(struct os_eventq **evq, struct os_event *start_ev)
-{
-    struct os_eventq *eventq_dflt;
+    prev_evq = *cur_evq;
+    *cur_evq = new_evq;
 
-    if (*evq == NULL) {
-        eventq_dflt = os_eventq_dflt_get();
-        if (eventq_dflt != NULL) {
-            os_eventq_designate(evq, eventq_dflt, start_ev);
+    if (start_ev != NULL) {
+        if (start_ev->ev_queued) {
+            assert(prev_evq != NULL);
+            os_eventq_remove(prev_evq, start_ev);
         }
-
-        /* The system is misconfigured if there is still no parent eventq.  The
-         * application should have explicitly specified a parent queue for each
-         * package, or indicated a default.
-         */
-        assert(*evq != NULL);
+        os_eventq_put(new_evq, start_ev);
     }
 }