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

retrier: use atomics as flags #518

Merged
merged 3 commits into from
Jun 25, 2024
Merged
Changes from 2 commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
18 changes: 6 additions & 12 deletions Android/app/src/go/intra/split/retrier.go
Original file line number Diff line number Diff line change
Expand Up @@ -62,8 +62,8 @@
// Flag indicating when retry is finished or unnecessary.
retryCompleteFlag chan struct{}
// Flags indicating whether the caller has called CloseRead and CloseWrite.
readCloseFlag chan struct{}
writeCloseFlag chan struct{}
readCloseFlag atomic.Bool

Check failure on line 65 in Android/app/src/go/intra/split/retrier.go

View workflow job for this annotation

GitHub Actions / test

undefined: atomic
writeCloseFlag atomic.Bool

Check failure on line 66 in Android/app/src/go/intra/split/retrier.go

View workflow job for this annotation

GitHub Actions / test

undefined: atomic
stats *RetryStats
}

Expand All @@ -87,11 +87,11 @@
}

func (r *retrier) readClosed() bool {
return closed(r.readCloseFlag)
return r.readCloseFlag.Load()
}

func (r *retrier) writeClosed() bool {
return closed(r.writeCloseFlag)
return r.writeCloseFlag.Load()
}

func (r *retrier) retryCompleted() bool {
Expand Down Expand Up @@ -142,8 +142,6 @@
conn: conn.(*net.TCPConn),
timeout: timeout(before, after),
retryCompleteFlag: make(chan struct{}),
readCloseFlag: make(chan struct{}),
writeCloseFlag: make(chan struct{}),
stats: stats,
}

Expand Down Expand Up @@ -211,9 +209,7 @@
}

func (r *retrier) CloseRead() error {
if !r.readClosed() {
close(r.readCloseFlag)
}
r.readCloseFlag.Store(true)
r.mutex.Lock()
defer r.mutex.Unlock()
return r.conn.CloseRead()
Expand Down Expand Up @@ -363,9 +359,7 @@
}

func (r *retrier) CloseWrite() error {
if !r.writeClosed() {
close(r.writeCloseFlag)
}
r.writeCloseFlag.Store(true)
r.mutex.Lock()
defer r.mutex.Unlock()
return r.conn.CloseWrite()
Expand Down
Loading