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 2019/06/07 16:19:43 UTC

[GitHub] [mynewt-nimble] ccollins476ad commented on a change in pull request #467: nimble/host: Add support to stop/de-init ports

ccollins476ad commented on a change in pull request #467: nimble/host: Add support to stop/de-init ports
URL: https://github.com/apache/mynewt-nimble/pull/467#discussion_r291662701
 
 

 ##########
 File path: porting/nimble/src/nimble_port.c
 ##########
 @@ -55,17 +58,75 @@ nimble_port_init(void)
 #endif
 }
 
+void
+nimble_port_deinit(void)
+{
+    ble_npl_eventq_deinit(&g_eventq_dflt);
+
+    ble_hs_deinit();
+}
+
 void
 nimble_port_run(void)
 {
     struct ble_npl_event *ev;
+    int arg;
 
     while (1) {
         ev = ble_npl_eventq_get(&g_eventq_dflt, BLE_NPL_TIME_FOREVER);
         ble_npl_event_run(ev);
+        arg = (int)ble_npl_event_get_arg(ev);
+        if (arg == NIMBLE_PORT_DEINIT_EV_ARG) {
+            break;
+        }
     }
 }
 
+/**
+ * Called when the host stop procedure has completed.
+ */
+static void
+ble_hs_stop_cb(int status, void *arg)
+{
+    ble_npl_sem_release(&ble_hs_stop_sem);
+}
+
+static void
+nimble_port_stop_cb(struct ble_npl_event *ev)
+{
+    ble_npl_sem_release(&ble_hs_stop_sem);
+}
+
+int
+nimble_port_stop(void)
+{
+    int rc;
+
+    ble_npl_sem_init(&ble_hs_stop_sem, 0);
+    /* Initiate a host stop procedure. */
+    rc = ble_hs_stop(&stop_listener, ble_hs_stop_cb,
+            NULL);
+    if (rc != 0) {
+        ble_npl_sem_deinit(&ble_hs_stop_sem);
+        return rc;
+    }
+
+    /* Wait till the host stop procedure is complete */
+    ble_npl_sem_pend(&ble_hs_stop_sem, BLE_NPL_TIME_FOREVER);
 
 Review comment:
   This function (`nimble_port_stop()`) can't be called from the same task that the host runs in, is that correct?  If so, that is probably worth mentioning in a comment.

----------------------------------------------------------------
This is an automated message from the Apache Git Service.
To respond to the message, please log on to 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