Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

remove the redundant uat_wg sync variable, comment on why es_wg is used #156

Closed
wants to merge 1 commit into from
Closed
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
16 changes: 7 additions & 9 deletions main/sdr.go
Expand Up @@ -28,7 +28,6 @@ var UATDev *UAT
var ESDev *ES

var uat_shutdown chan int
var uat_wg *sync.WaitGroup = &sync.WaitGroup{}

var es_shutdown chan int
var es_wg *sync.WaitGroup = &sync.WaitGroup{}
Expand Down Expand Up @@ -70,7 +69,6 @@ func (e *ES) read() {
select {
case buf := <-outputChan:
replayLog(string(buf), MSGCLASS_DUMP1090)

case <-es_shutdown:
log.Println("ES read(): shutdown msg received, calling cmd.Process.Kill() ...")
err := cmd.Process.Kill()
Expand All @@ -83,13 +81,11 @@ func (e *ES) read() {
return
default:
time.Sleep(1 * time.Second)

}
}
}

func (u *UAT) read() {
defer uat_wg.Done()
log.Println("Entered UAT read() ...")
var buffer = make([]uint8, rtl.DefaultBufLength)
for {
Expand Down Expand Up @@ -256,17 +252,18 @@ func (e *ES) writeID() error {
func (u *UAT) shutdown() {
log.Println("Entered UAT shutdown() ...")
close(uat_shutdown) // signal to shutdown
log.Println("UAT shutdown(): calling uat_wg.Wait() ...")
uat_wg.Wait() // Wait for the goroutine to shutdown
log.Println("UAT shutdown(): uat_wg.Wait() returned...")
log.Println("UAT shutdown(): closing device ...")
u.dev.Close() // preempt the blocking ReadSync call
u.dev.Close()
log.Println("UAT device is closed...")
}

func (e *ES) shutdown() {
log.Println("Entered ES shutdown() ...")
close(es_shutdown) // signal to shutdown
log.Println("ES shutdown(): calling es_wg.Wait() ...")
// An important part of the shutdown is killing the
// dump1090 process and we wait for that to happen
// via the es_wg sync variable.
es_wg.Wait() // Wait for the goroutine to shutdown
log.Println("ES shutdown(): es_wg.Wait() returned...")
}
Expand Down Expand Up @@ -347,8 +344,8 @@ func sdrWatcher() {
log.Printf("UATDev = &UAT{indexID: id} failed: %s\n", err)
UATDev = nil
} else {
// synchronous channel
uat_shutdown = make(chan int)
uat_wg.Add(1)
go UATDev.read()
}
}
Expand Down Expand Up @@ -391,6 +388,7 @@ func sdrWatcher() {
log.Printf("ESDev = &ES{indexID: id} failed: %s\n", err)
ESDev = nil
} else {
// synchronous channel
es_shutdown = make(chan int)
es_wg.Add(1)
go ESDev.read()
Expand Down