From 9751d761a0db4eae9b6aaf6d263d959423704df3 Mon Sep 17 00:00:00 2001 From: Thorsten Ball Date: Thu, 10 Jun 2021 06:37:31 +0200 Subject: [PATCH 1/3] Fix busy loop by signalling to scheduler --- main.go | 2 ++ 1 file changed, 2 insertions(+) diff --git a/main.go b/main.go index 6dd4758..0e5f447 100644 --- a/main.go +++ b/main.go @@ -3,6 +3,7 @@ package main import ( "flag" "log" + "runtime" "github.com/currantlabs/ble/linux" ) @@ -46,6 +47,7 @@ func main() { // Loop forever while notification handler respond for { + runtime.Gosched() } // for _, device := range config.Devices { From 58b48604afdaa11a979f60e0d2c639982d7399d0 Mon Sep 17 00:00:00 2001 From: Thorsten Ball Date: Thu, 10 Jun 2021 06:42:12 +0200 Subject: [PATCH 2/3] Improve busy loop --- main.go | 6 ++++-- 1 file changed, 4 insertions(+), 2 deletions(-) diff --git a/main.go b/main.go index 0e5f447..2f4a9c3 100644 --- a/main.go +++ b/main.go @@ -3,7 +3,7 @@ package main import ( "flag" "log" - "runtime" + "time" "github.com/currantlabs/ble/linux" ) @@ -47,7 +47,9 @@ func main() { // Loop forever while notification handler respond for { - runtime.Gosched() + select { + case <-time.After(time.Second): + } } // for _, device := range config.Devices { From f8d289d01024808b28b810a32eacde7b7d6ffeda Mon Sep 17 00:00:00 2001 From: Thorsten Ball Date: Thu, 10 Jun 2021 07:55:07 +0200 Subject: [PATCH 3/3] Use waitgroup in busy loop --- main.go | 8 ++++---- 1 file changed, 4 insertions(+), 4 deletions(-) diff --git a/main.go b/main.go index 2f4a9c3..1728ee9 100644 --- a/main.go +++ b/main.go @@ -3,7 +3,7 @@ package main import ( "flag" "log" - "time" + "sync" "github.com/currantlabs/ble/linux" ) @@ -46,10 +46,10 @@ func main() { } // Loop forever while notification handler respond + wg := sync.WaitGroup{} + wg.Add(1) for { - select { - case <-time.After(time.Second): - } + wg.Wait() } // for _, device := range config.Devices {