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/07 01:52:34 UTC

[mynewt-newtmgr] 03/03: nmxact - Protect discoverer in BleScanner#Stop().

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 2d5217f7c141ecea67a8cf6923169434ed20b79c
Author: Christopher Collins <cc...@apache.org>
AuthorDate: Wed Sep 6 18:50:04 2017 -0700

    nmxact - Protect discoverer in BleScanner#Stop().
---
 nmxact/nmble/ble_scanner.go | 27 +++++++++++++++------------
 1 file changed, 15 insertions(+), 12 deletions(-)

diff --git a/nmxact/nmble/ble_scanner.go b/nmxact/nmble/ble_scanner.go
index ef8b769..5b529f4 100644
--- a/nmxact/nmble/ble_scanner.go
+++ b/nmxact/nmble/ble_scanner.go
@@ -290,26 +290,29 @@ func (s *BleScanner) Start(cfg scan.Cfg) error {
 }
 
 func (s *BleScanner) suspend() error {
-	s.suspendBlocker.Start()
-	defer s.suspendBlocker.Unblock(nil)
+	initiate := func() {
+		s.mtx.Lock()
+		defer s.mtx.Unlock()
 
-	discoverer := s.discoverer
-	ses := s.ses
+		if s.discoverer != nil {
+			s.discoverer.Stop()
+			s.discoverer = nil
+		}
 
-	if discoverer != nil {
-		discoverer.Stop()
+		if s.ses != nil {
+			s.ses.Close()
+			s.ses = nil
+		}
 	}
 
-	if ses != nil {
-		ses.Close()
-	}
+	s.suspendBlocker.Start()
+	defer s.suspendBlocker.Unblock(nil)
+
+	initiate()
 
 	// Block until scan is fully terminated.
 	s.scanBlocker.Wait(nmxutil.DURATION_FOREVER, nil)
 
-	s.discoverer = nil
-	s.ses = nil
-
 	return nil
 }
 

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