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/09/20 03:27:51 UTC

[mynewt-newtmgr] branch master updated: nmxact - Stop syncer on BLE xport restart.

This is an automated email from the ASF dual-hosted git repository.

ccollins pushed a commit to branch master
in repository https://gitbox.apache.org/repos/asf/mynewt-newtmgr.git


The following commit(s) were added to refs/heads/master by this push:
     new d1f7845  nmxact - Stop syncer on BLE xport restart.
d1f7845 is described below

commit d1f784562bfb65866c04553426214bd72af4dd16
Author: Christopher Collins <cc...@apache.org>
AuthorDate: Tue Sep 19 20:27:07 2017 -0700

    nmxact - Stop syncer on BLE xport restart.
---
 nmxact/nmble/ble_xport.go | 12 +++++++-----
 nmxact/nmble/sync.go      | 24 +++++++++++++-----------
 2 files changed, 20 insertions(+), 16 deletions(-)

diff --git a/nmxact/nmble/ble_xport.go b/nmxact/nmble/ble_xport.go
index 06a562d..578e837 100644
--- a/nmxact/nmble/ble_xport.go
+++ b/nmxact/nmble/ble_xport.go
@@ -267,19 +267,21 @@ func (bx *BleXport) shutdown(cause error) error {
 	log.Debugf("Aborting BLE master")
 	bx.master.Abort(cause)
 
-	// Indicate an error to all of this transport's listeners.  This
-	// prevents them from blocking endlessly while awaiting a BLE message.
-	log.Debugf("Stopping BLE dispatcher")
-	bx.d.ErrorAll(cause)
-
 	// Reset controller so that all outstanding connections terminate.
 	if bx.syncer.Synced() {
+		log.Debugf("Resetting host")
 		ResetXact(bx)
 	}
 
 	// Stop monitoring host-controller sync.
+	log.Debugf("Stopping BLE syncer")
 	bx.syncer.Stop()
 
+	// Indicate an error to all of this transport's listeners.  This
+	// prevents them from blocking endlessly while awaiting a BLE message.
+	log.Debugf("Stopping BLE dispatcher")
+	bx.d.ErrorAll(cause)
+
 	// Stop all of this transport's go routines.
 	close(bx.stopChan)
 
diff --git a/nmxact/nmble/sync.go b/nmxact/nmble/sync.go
index 2e138ea..64044ab 100644
--- a/nmxact/nmble/sync.go
+++ b/nmxact/nmble/sync.go
@@ -30,9 +30,9 @@ import (
 const syncPollRate = time.Second
 
 type Syncer struct {
-	x      *BleXport
-	synced bool
-	active bool
+	x       *BleXport
+	synced  bool
+	enabled bool
 
 	stopCh  chan struct{}
 	syncCh  chan bool
@@ -40,7 +40,7 @@ type Syncer struct {
 
 	wg sync.WaitGroup
 
-	// Protects synced and active.
+	// Protects synced and enabled.
 	mtx sync.Mutex
 }
 
@@ -110,24 +110,24 @@ func (s *Syncer) listen() error {
 
 		for {
 			select {
-			case <-syncl.ErrChan:
+			case err, ok := <-syncl.ErrChan:
 				// XXX
-			case bm := <-syncl.MsgChan:
+			case bm, ok := <-syncl.MsgChan:
 				switch msg := bm.(type) {
 				case *BleSyncEvt:
 					s.setSynced(msg.Synced)
 				}
 
-			case <-resetl.ErrChan:
+			case _, ok := <-resetl.ErrChan:
 				// XXX
-			case bm := <-resetl.MsgChan:
+			case bm, ok := <-resetl.MsgChan:
 				switch msg := bm.(type) {
 				case *BleResetEvt:
 					s.setSynced(false)
 					s.resetCh <- msg.Reason
 				}
 
-			case <-s.stopCh:
+			case _, ok := <-s.stopCh:
 				// It is OK to strand the two listeners.  Their deferred
 				// removal will drain them.
 				return
@@ -151,6 +151,8 @@ func (s *Syncer) Start(x *BleXport) (<-chan bool, <-chan int, error) {
 		return nil, nil, err
 	}
 
+	s.enabled = true
+
 	return s.syncCh, s.resetCh, nil
 }
 
@@ -159,11 +161,11 @@ func (s *Syncer) Stop() error {
 		s.mtx.Lock()
 		defer s.mtx.Unlock()
 
-		if !s.active {
+		if !s.enabled {
 			return fmt.Errorf("Syncer already stopped")
 		}
 
-		s.active = false
+		s.enabled = false
 		return nil
 	}
 

-- 
To stop receiving notification emails like this one, please contact
['"commits@mynewt.apache.org" <co...@mynewt.apache.org>'].