Skip to content

Commit 1e0029f

Browse files
committed
fix variable to use atomic
1 parent f404006 commit 1e0029f

File tree

2 files changed

+9
-8
lines changed

2 files changed

+9
-8
lines changed

pkg/lobster/tailer/tail/tail.go

+7-7
Original file line numberDiff line numberDiff line change
@@ -11,6 +11,7 @@ import (
1111
"os"
1212
"strings"
1313
"sync"
14+
"sync/atomic"
1415
"time"
1516

1617
"github.com/golang/glog"
@@ -77,7 +78,7 @@ type Config struct {
7778
type Tail struct {
7879
Filename string
7980
Lines chan *Line
80-
IsTailing bool
81+
IsTailing int32
8182
Config
8283

8384
file *os.File
@@ -108,9 +109,10 @@ func TailFile(filename string, config Config) (*Tail, error) {
108109
}
109110

110111
t := &Tail{
111-
Filename: filename,
112-
Lines: make(chan *Line),
113-
Config: config,
112+
Filename: filename,
113+
Lines: make(chan *Line),
114+
Config: config,
115+
IsTailing: 1,
114116
}
115117

116118
// when Logger was not specified in config, use default logger
@@ -233,12 +235,10 @@ func (tail *Tail) readLine() (string, error) {
233235
}
234236

235237
func (tail *Tail) tailFileSync() {
236-
defer func() { tail.IsTailing = false }()
238+
defer func() { atomic.StoreInt32(&tail.IsTailing, 0) }()
237239
defer tail.Done()
238240
defer tail.close()
239241

240-
tail.IsTailing = true
241-
242242
if !tail.MustExist {
243243
// deferred first open.
244244
err := tail.reopen()

pkg/lobster/tailer/tailer.go

+2-1
Original file line numberDiff line numberDiff line change
@@ -21,6 +21,7 @@ import (
2121
"log"
2222
"os"
2323
"sync"
24+
"sync/atomic"
2425
"time"
2526

2627
"github.com/golang/glog"
@@ -183,7 +184,7 @@ func (t *Tailer) drain() {
183184
close(t.LogChan)
184185
}
185186

186-
for t.tail.IsTailing {
187+
for atomic.LoadInt32(&t.tail.IsTailing) == 1 {
187188
select {
188189
case <-t.tail.Lines:
189190
default:

0 commit comments

Comments
 (0)