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 2016/11/01 17:54:39 UTC

incubator-mynewt-core git commit: oic - Remove dedicated task

Repository: incubator-mynewt-core
Updated Branches:
  refs/heads/develop 1242fddde -> e5083dc4a


oic - Remove dedicated task

Prior to this change, the OIC library created its own task.  Now, it
runs in whichever task the application tells it to run in.


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/e5083dc4
Tree: http://git-wip-us.apache.org/repos/asf/incubator-mynewt-core/tree/e5083dc4
Diff: http://git-wip-us.apache.org/repos/asf/incubator-mynewt-core/diff/e5083dc4

Branch: refs/heads/develop
Commit: e5083dc4ac5de284b1ef70f2ed6bd99a4aaa1903
Parents: 1242fdd
Author: Christopher Collins <cc...@apache.org>
Authored: Tue Nov 1 10:55:12 2016 -0700
Committer: Christopher Collins <cc...@apache.org>
Committed: Tue Nov 1 10:55:29 2016 -0700

----------------------------------------------------------------------
 apps/ocf_sample/src/main.c               | 50 ++++++++++++++++-----
 apps/ocf_sample/src/ocf_ble.c            |  4 +-
 net/oic/include/oic/oc_gatt.h            |  6 +--
 net/oic/src/port/mynewt/adaptor.c        | 64 +++++++--------------------
 net/oic/src/port/mynewt/adaptor.h        |  3 +-
 net/oic/src/port/mynewt/ble_adaptor.c    |  8 ++--
 net/oic/src/port/mynewt/ip_adaptor.c     |  2 +-
 net/oic/src/port/mynewt/serial_adaptor.c |  2 +-
 8 files changed, 65 insertions(+), 74 deletions(-)
----------------------------------------------------------------------


http://git-wip-us.apache.org/repos/asf/incubator-mynewt-core/blob/e5083dc4/apps/ocf_sample/src/main.c
----------------------------------------------------------------------
diff --git a/apps/ocf_sample/src/main.c b/apps/ocf_sample/src/main.c
index d9888f7..cc34bdb 100644
--- a/apps/ocf_sample/src/main.c
+++ b/apps/ocf_sample/src/main.c
@@ -34,10 +34,18 @@
 #include "ocf_sample.h"
 #endif
 
-#define OCF_TASK_PRIO      (8)
-#define OCF_TASK_STACK_SIZE (OS_STACK_ALIGN(512))
-static os_stack_t ocf_stack[OCF_TASK_STACK_SIZE];
-struct os_task ocf_task;
+/** Task for handling OCF-specific events. */
+#define OCF_MAIN_TASK_PRIO          (8)
+#define OCF_MAIN_TASK_STACK_SIZE    (OS_STACK_ALIGN(512))
+static os_stack_t ocf_stack[OCF_MAIN_TASK_STACK_SIZE];
+struct os_task ocf_main_task;
+
+/** Auxilliary task for handling events from library packages. */
+#define OCF_AUX_TASK_PRIO           (9)
+#define OCF_AUX_TASK_STACK_SIZE     (OS_STACK_ALIGN(336))
+struct os_eventq ocf_aux_evq;
+static os_stack_t ocf_aux_stack[OCF_AUX_TASK_STACK_SIZE];
+struct os_task ocf_aux_task;
 
 #if (MYNEWT_VAL(OC_CLIENT) == 1)
 static void issue_requests(void);
@@ -230,8 +238,8 @@ oc_signal_main_loop(void)
      os_sem_release(&ocf_main_loop_sem);
 }
 
-void
-ocf_task_handler(void *arg)
+static void
+ocf_main_task_handler(void *arg)
 {
     os_sem_init(&ocf_main_loop_sem, 1);
 
@@ -250,16 +258,36 @@ ocf_task_handler(void *arg)
     oc_main_shutdown();
 }
 
-void
-ocf_task_init(void)
+static void
+ocf_aux_task_handler(void *arg)
+{
+    while (1) {
+        os_eventq_run(&ocf_aux_evq);
+    }
+}
+
+static void
+ocf_main_task_init(void)
 {
     int rc;
 
-    rc = os_task_init(&ocf_task, "ocf", ocf_task_handler, NULL,
-            OCF_TASK_PRIO, OS_WAIT_FOREVER, ocf_stack, OCF_TASK_STACK_SIZE);
+    rc = os_task_init(&ocf_main_task, "ocf", ocf_main_task_handler, NULL,
+            OCF_MAIN_TASK_PRIO, OS_WAIT_FOREVER, ocf_stack,
+            OCF_MAIN_TASK_STACK_SIZE);
     assert(rc == 0);
 
     oc_main_init(&ocf_handler);
+
+    /* Initialize eventq */
+    os_eventq_init(&ocf_aux_evq);
+
+    /* Set the default eventq for packages that lack a dedicated task. */
+    os_eventq_dflt_set(&ocf_aux_evq);
+
+    rc = os_task_init(&ocf_aux_task, "ocf_aux", ocf_aux_task_handler, NULL,
+            OCF_AUX_TASK_PRIO, OS_WAIT_FOREVER, ocf_aux_stack,
+            OCF_AUX_TASK_STACK_SIZE);
+    assert(rc == 0);
 }
 
 int
@@ -276,7 +304,7 @@ main(int argc, char **argv)
     ocf_ble_init();
 #endif
 
-    ocf_task_init();
+    ocf_main_task_init();
 
     /* Start the OS */
     os_start();

http://git-wip-us.apache.org/repos/asf/incubator-mynewt-core/blob/e5083dc4/apps/ocf_sample/src/ocf_ble.c
----------------------------------------------------------------------
diff --git a/apps/ocf_sample/src/ocf_ble.c b/apps/ocf_sample/src/ocf_ble.c
index 8d02d2f..6ae636b 100644
--- a/apps/ocf_sample/src/ocf_ble.c
+++ b/apps/ocf_sample/src/ocf_ble.c
@@ -256,7 +256,6 @@ static const uint8_t ocf_ble_addr[6] = {1,2,3,4,5,6};
 void
 ocf_ble_init(void)
 {
-    struct os_eventq *evq;
     int rc;
 
     /* Initialize the ocf_ble log. */
@@ -266,7 +265,7 @@ ocf_ble_init(void)
     memcpy(g_dev_addr, ocf_ble_addr, sizeof(g_dev_addr));
 
     /* COAP Gatt server initialization */
-    rc = ble_coap_gatt_srv_init(&evq);
+    rc = ble_coap_gatt_srv_init();
     assert(rc == 0);
 
     /* Set the default device name. */
@@ -277,7 +276,6 @@ ocf_ble_init(void)
     log_register("ble_hs", &ble_hs_log, &log_console_handler, NULL,
                  LOG_SYSLEVEL);
 
-    ble_hs_cfg.parent_evq = evq;
     ble_hs_cfg.sync_cb = ocf_ble_on_sync;
 }
 

http://git-wip-us.apache.org/repos/asf/incubator-mynewt-core/blob/e5083dc4/net/oic/include/oic/oc_gatt.h
----------------------------------------------------------------------
diff --git a/net/oic/include/oic/oc_gatt.h b/net/oic/include/oic/oc_gatt.h
index 4393ac3..0261678 100644
--- a/net/oic/include/oic/oc_gatt.h
+++ b/net/oic/include/oic/oc_gatt.h
@@ -24,11 +24,7 @@
 extern "C" {
 #endif
 
-struct ble_hs_cfg;
-
-/* returns the event q for bluetooth to use */
-int
-ble_coap_gatt_srv_init(struct os_eventq **out);
+int ble_coap_gatt_srv_init(void);
 
 #ifdef __cplusplus
 }

http://git-wip-us.apache.org/repos/asf/incubator-mynewt-core/blob/e5083dc4/net/oic/src/port/mynewt/adaptor.c
----------------------------------------------------------------------
diff --git a/net/oic/src/port/mynewt/adaptor.c b/net/oic/src/port/mynewt/adaptor.c
index 1ca90f2..ea33f58 100644
--- a/net/oic/src/port/mynewt/adaptor.c
+++ b/net/oic/src/port/mynewt/adaptor.c
@@ -28,12 +28,25 @@
 #include "../oc_log.h"
 #include "adaptor.h"
 
-struct os_eventq oc_event_q;
+static struct os_eventq *oc_evq;
 
 /* not sure if these semaphores are necessary yet.  If we are running
  * all of this from one task, we may not need these */
 static struct os_mutex oc_net_mutex;
 
+struct os_eventq *
+oc_evq_get(void)
+{
+    os_eventq_ensure(&oc_evq, NULL);
+    return oc_evq;
+}
+
+void
+oc_evq_set(struct os_eventq *evq)
+{
+    os_eventq_designate(&oc_evq, evq, NULL);
+}
+
 void
 oc_network_event_handler_mutex_init(void)
 {
@@ -54,12 +67,6 @@ oc_network_event_handler_mutex_unlock(void)
     os_mutex_release(&oc_net_mutex);
 }
 
-/* need a task to process OCF messages */
-#define OC_NET_TASK_STACK_SIZE  OS_STACK_ALIGN(MYNEWT_VAL(OC_TASK_STACK_SIZE))
-#define OC_NET_TASK_PRIORITY            MYNEWT_VAL(OC_TASK_PRIORITY)
-struct os_task oc_task;
-os_stack_t *oc_stack;
-
 void
 oc_send_buffer(oc_message_t *message)
 {
@@ -108,40 +115,6 @@ void oc_send_multicast_message(oc_message_t *message)
 #endif
 }
 
-/* send all the entries to the OCF stack through the same task */
-void
-oc_task_handler(void *arg)
-{
-    while (1) {
-        os_eventq_run(&oc_event_q);
-    }
-}
-
-static int
-oc_init_task(void)
-{
-    int rc;
-
-    os_eventq_init(&oc_event_q);
-
-    oc_stack = (os_stack_t*) malloc(sizeof(os_stack_t)*OC_NET_TASK_STACK_SIZE);
-    if (NULL == oc_stack) {
-        ERROR("Could not malloc oc stack\n");
-        return -1;
-    }
-
-    rc = os_task_init(&oc_task, "oc", oc_task_handler, NULL,
-            OC_NET_TASK_PRIORITY, OS_WAIT_FOREVER,
-            oc_stack, OC_NET_TASK_STACK_SIZE);
-
-    if (rc != 0) {
-        ERROR("Could not start oc task\n");
-        free(oc_stack);
-    }
-
-    return rc;
-}
-
 void
 oc_connectivity_shutdown(void)
 {
@@ -176,14 +149,11 @@ oc_connectivity_init(void)
         rc = 0;
     }
 #endif
-    rc = oc_init_task();
+
     if (rc != 0) {
-        goto oc_connectivity_init_err;
+        oc_connectivity_shutdown();
+        return rc;
     }
 
     return 0;
-
-oc_connectivity_init_err:
-    oc_connectivity_shutdown();
-    return rc;
 }

http://git-wip-us.apache.org/repos/asf/incubator-mynewt-core/blob/e5083dc4/net/oic/src/port/mynewt/adaptor.h
----------------------------------------------------------------------
diff --git a/net/oic/src/port/mynewt/adaptor.h b/net/oic/src/port/mynewt/adaptor.h
index 6a0d246..259691c 100644
--- a/net/oic/src/port/mynewt/adaptor.h
+++ b/net/oic/src/port/mynewt/adaptor.h
@@ -24,7 +24,8 @@
 extern "C" {
 #endif
 
-extern struct os_eventq oc_event_q;
+struct os_eventq *oc_evq_get(void);
+void oc_evq_set(struct os_eventq *evq);
 
 
 #if (MYNEWT_VAL(OC_TRANSPORT_IP) == 1)

http://git-wip-us.apache.org/repos/asf/incubator-mynewt-core/blob/e5083dc4/net/oic/src/port/mynewt/ble_adaptor.c
----------------------------------------------------------------------
diff --git a/net/oic/src/port/mynewt/ble_adaptor.c b/net/oic/src/port/mynewt/ble_adaptor.c
index 634a20b..e4e0e0f 100644
--- a/net/oic/src/port/mynewt/ble_adaptor.c
+++ b/net/oic/src/port/mynewt/ble_adaptor.c
@@ -92,7 +92,7 @@ gatt_svr_chr_access_coap(uint16_t conn_handle, uint16_t attr_handle,
             if (rc) {
                 return BLE_ATT_ERR_INSUFFICIENT_RES;
             }
-            rc = os_mqueue_put(&ble_coap_mq, &oc_event_q, m);
+            rc = os_mqueue_put(&ble_coap_mq, oc_evq_get(), m);
             if (rc) {
                 return BLE_ATT_ERR_PREPARE_QUEUE_FULL;
             }
@@ -182,7 +182,7 @@ rx_attempt_err:
 #endif
 
 int
-ble_coap_gatt_srv_init(struct os_eventq **out)
+ble_coap_gatt_srv_init(void)
 {
 #if (MYNEWT_VAL(OC_SERVER) == 1)
     int rc;
@@ -197,7 +197,6 @@ ble_coap_gatt_srv_init(struct os_eventq **out)
     }
 #endif
 
-    *out = &oc_event_q;
     return 0;
 }
 
@@ -214,8 +213,7 @@ oc_event_gatt(struct os_event *ev)
 int
 oc_connectivity_init_gatt(void)
 {
-    os_mqueue_init(&ble_coap_mq, NULL);
-    ble_coap_mq.mq_ev.ev_cb = oc_event_gatt;
+    os_mqueue_init(&ble_coap_mq, oc_event_gatt, NULL);
     return 0;
 }
 

http://git-wip-us.apache.org/repos/asf/incubator-mynewt-core/blob/e5083dc4/net/oic/src/port/mynewt/ip_adaptor.c
----------------------------------------------------------------------
diff --git a/net/oic/src/port/mynewt/ip_adaptor.c b/net/oic/src/port/mynewt/ip_adaptor.c
index 3585c51..e05f606 100644
--- a/net/oic/src/port/mynewt/ip_adaptor.c
+++ b/net/oic/src/port/mynewt/ip_adaptor.c
@@ -208,7 +208,7 @@ union mn_socket_cb oc_sock_cbs = {
 void
 oc_socks_readable(void *cb_arg, int err)
 {
-    os_eventq_put(&oc_event_q, &oc_sock_read_event);
+    os_eventq_put(&oc_evq_get(), &oc_sock_read_event);
 }
 
 void

http://git-wip-us.apache.org/repos/asf/incubator-mynewt-core/blob/e5083dc4/net/oic/src/port/mynewt/serial_adaptor.c
----------------------------------------------------------------------
diff --git a/net/oic/src/port/mynewt/serial_adaptor.c b/net/oic/src/port/mynewt/serial_adaptor.c
index 15f95e0..5bb676d 100644
--- a/net/oic/src/port/mynewt/serial_adaptor.c
+++ b/net/oic/src/port/mynewt/serial_adaptor.c
@@ -33,7 +33,7 @@ struct os_mqueue oc_serial_mqueue;
 static int
 oc_serial_in(struct os_mbuf *m, void *arg)
 {
-    return os_mqueue_put(&oc_serial_mqueue, &oc_event_q, m);
+    return os_mqueue_put(&oc_serial_mqueue, oc_evq(), m);
 }
 
 void