Movatterモバイル変換


[0]ホーム

URL:


Skip to content

Navigation Menu

Sign in
Appearance settings

Search code, repositories, users, issues, pull requests...

Provide feedback

We read every piece of feedback, and take your input very seriously.

Saved searches

Use saved searches to filter your results more quickly

Sign up
Appearance settings

Commit1b94ccc

Browse files
authored
fix(serialport): data race on theisClosing bool status of the serial port (#1009)
* fix: use atomic boolean for thread-safe isClosing flag
1 parentf1ca3c9 commit1b94ccc

File tree

1 file changed

+5
-3
lines changed

1 file changed

+5
-3
lines changed

‎serialport.go‎

Lines changed: 5 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -20,6 +20,7 @@ import (
2020
"encoding/base64"
2121
"io"
2222
"strconv"
23+
"sync/atomic"
2324
"time"
2425
"unicode/utf8"
2526

@@ -43,7 +44,7 @@ type serport struct {
4344

4445
// Keep track of whether we're being actively closed
4546
// just so we don't show scary error messages
46-
isClosingbool
47+
isClosingatomic.Bool
4748

4849
isClosingDueToErrorbool
4950

@@ -85,7 +86,7 @@ func (p *serport) reader(buftype string) {
8586
bufferPart:=serialBuffer[:n]
8687

8788
//if we detect that port is closing, break out of this for{} loop.
88-
ifp.isClosing {
89+
ifp.isClosing.Load() {
8990
strmsg:="Shutting down reader on "+p.portConf.Name
9091
log.Println(strmsg)
9192
h.broadcastSys<- []byte(strmsg)
@@ -348,7 +349,8 @@ func spHandlerOpen(portname string, baud int, buftype string) {
348349
}
349350

350351
func (p*serport)Close() {
351-
p.isClosing=true
352+
p.isClosing.Store(true)
353+
352354
p.bufferwatcher.Close()
353355
p.portIo.Close()
354356
serialPorts.MarkPortAsClosed(p.portName)

0 commit comments

Comments
 (0)

[8]ページ先頭

©2009-2025 Movatter.jp