Skip to content

all: switch to Go 1.19 atomics#48139

Merged
thaJeztah merged 12 commits intomoby:masterfrom
corhere:go119atomics
Jul 15, 2024
Merged

all: switch to Go 1.19 atomics#48139
thaJeztah merged 12 commits intomoby:masterfrom
corhere:go119atomics

Conversation

@corhere
Copy link
Copy Markdown
Contributor

@corhere corhere commented Jul 5, 2024

- What I did
Got rid of all instances of old-style atomic operations which operate on pointers to primitive variables. Added a lint rule to forbid old-style atomic operations in the codebase.

- How I did it
I replaced each instance with the most semantically-appropriate Go 1.19 atomic type for the situation, with one exception. The libnetwork diagnostic server was using atomics unsoundly. Most of the variable accesses were synchronized through a mutex, so I just replaced the singular atomic operation with a non-atomic operation, synchronized through the aforementioned mutex.

- How to verify it
Unit tests

- Description for the changelog

- A picture of a cute animal (not mandatory but encouraged)

@corhere corhere added the kind/refactor PR's that refactor, or clean-up code label Jul 5, 2024
@corhere corhere requested a review from thaJeztah July 5, 2024 23:28
Copy link
Copy Markdown
Member

@thaJeztah thaJeztah left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

LGTM

one question about the int32 -> uint32 (but just to double check)

createFile(t, name, "hi there")

var conversions int32
var conversions atomic.Uint32
Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This changed to a uint; I'm guessing that was intentional?

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Correct

func (s *Server) IsDiagnosticEnabled() bool {
s.mu.Lock()
defer s.mu.Unlock()
return s.enable == 1
Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

🤦 self invented booleans

Copy link
Copy Markdown
Member

@akerouanton akerouanton left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Overall LGTM, but left a few nits.

If it's worth changing conversions from int32 to atomic.Uint32 because it's never decremented, it's probably worth doing the same for the other vars.

Comment thread distribution/pull_v2_test.go Outdated
Comment thread distribution/xfer/transfer_test.go Outdated
Comment thread libnetwork/networkdb/networkdb_test.go Outdated
Comment thread libnetwork/networkdb/networkdb_test.go Outdated
@vvoland vvoland added this to the 28.0.0 milestone Jul 8, 2024
corhere added 5 commits July 8, 2024 11:09
It was unnecessary; access to the variable was synchronized through a
mutex in all cases but one, where synchonizing through the mutex would
work just fine without any chance of deadlocks.

Signed-off-by: Cory Snider <[email protected]>
@thaJeztah thaJeztah merged commit 20a0102 into moby:master Jul 15, 2024
@corhere corhere deleted the go119atomics branch July 15, 2024 16:29
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

kind/refactor PR's that refactor, or clean-up code status/2-code-review

Projects

None yet

Development

Successfully merging this pull request may close these issues.

4 participants