Use mutex on Close() to avoid data races on windows

This commit is contained in:
Tobias Kaupat
2017-11-30 12:08:22 +01:00
committed by Cristian Maglie
parent 545e830e04
commit f0282e0b50

View File

@@ -17,9 +17,13 @@ package serial
*/
import ("syscall")
import (
"syscall"
"sync"
)
type windowsPort struct {
mu sync.Mutex
handle syscall.Handle
}
@@ -58,8 +62,10 @@ func nativeGetPortsList() ([]string, error) {
}
func (port *windowsPort) Close() error {
port.mu.Lock()
defer func() {
port.handle = 0
port.mu.Unlock()
}()
if port.handle == 0 {
return nil