mynewt-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From ccoll...@apache.org
Subject [mynewt-newtmgr] 01/02: ble_scanner - Protect adv rpt cb with mutex.
Date Tue, 11 Jul 2017 23:39:14 GMT
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 726d9d53b31bdf252adcc6109d2880092e038ff1
Author: Christopher Collins <ccollins@apache.org>
AuthorDate: Tue Jul 11 16:24:38 2017 -0700

    ble_scanner - Protect adv rpt cb with mutex.
---
 nmxact/nmble/ble_scanner.go | 12 +++++++-----
 1 file changed, 7 insertions(+), 5 deletions(-)

diff --git a/nmxact/nmble/ble_scanner.go b/nmxact/nmble/ble_scanner.go
index 478f1dd..da8532c 100644
--- a/nmxact/nmble/ble_scanner.go
+++ b/nmxact/nmble/ble_scanner.go
@@ -54,8 +54,12 @@ func (s *BleScanner) discover() (*BleDev, error) {
 	var dev *BleDev
 	advRptCb := func(r BleAdvReport) {
 		if s.cfg.Ble.ScanPred(r) {
+			s.mtx.Lock()
+
 			dev = &r.Sender
 			s.discoverer.Stop()
+
+			s.mtx.Unlock()
 		}
 	}
 	if err := s.discoverer.Start(advRptCb); err != nil {
@@ -191,21 +195,19 @@ func (s *BleScanner) Stop() error {
 	s.enabled = false
 
 	s.mtx.Lock()
+	defer s.mtx.Unlock()
 
 	discoverer := s.discoverer
-	s.discoverer = nil
-
 	bos := s.bos
-	s.bos = nil
-
-	s.mtx.Unlock()
 
 	if discoverer != nil {
 		discoverer.Stop()
+		s.discoverer = nil
 	}
 
 	if bos != nil {
 		bos.Close()
+		s.bos = nil
 	}
 
 	return nil

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

Mime
View raw message