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/08/29 20:51:14 UTC

[mynewt-newtmgr] 01/02: nmxact - Protect scanner.discoverer with mutex.

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

commit b52338c2fd396685cf9f841624129bac7b852bd7
Author: Christopher Collins <cc...@apache.org>
AuthorDate: Tue Aug 29 13:26:22 2017 -0700

    nmxact - Protect scanner.discoverer with mutex.
---
 nmxact/nmble/ble_scanner.go | 17 +++++++++++------
 1 file changed, 11 insertions(+), 6 deletions(-)

diff --git a/nmxact/nmble/ble_scanner.go b/nmxact/nmble/ble_scanner.go
index ba187a3..ef8b769 100644
--- a/nmxact/nmble/ble_scanner.go
+++ b/nmxact/nmble/ble_scanner.go
@@ -82,6 +82,13 @@ func (s *BleScanner) toggleEnabled(to bool) bool {
 	return true
 }
 
+func (s *BleScanner) setDiscoverer(d *Discoverer) {
+	s.mtx.Lock()
+	defer s.mtx.Unlock()
+
+	s.discoverer = d
+}
+
 func (s *BleScanner) setSession(ses *BleSesn) {
 	s.mtx.Lock()
 	defer s.mtx.Unlock()
@@ -105,16 +112,13 @@ func (s *BleScanner) addFailedDev(dev BleDev) {
 }
 
 func (s *BleScanner) discover() (*BleDev, error) {
-	s.mtx.Lock()
-	s.discoverer = NewDiscoverer(DiscovererParams{
+	s.setDiscoverer(NewDiscoverer(DiscovererParams{
 		Bx:          s.bx,
 		OwnAddrType: s.cfg.SesnCfg.Ble.OwnAddrType,
 		Passive:     false,
 		Duration:    15 * time.Second,
-	})
-	s.mtx.Unlock()
-
-	defer func() { s.discoverer = nil }()
+	}))
+	defer s.setDiscoverer(nil)
 
 	var dev *BleDev
 	advRptCb := func(r BleAdvReport) {
@@ -142,6 +146,7 @@ func (s *BleScanner) connect(dev BleDev) error {
 
 	s.setSession(ses)
 	if err := s.ses.Open(); err != nil {
+		s.setSession(nil)
 		return err
 	}
 

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