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

Use atomics instead of locking #50

Open
nhynes opened this issue Nov 8, 2021 · 0 comments
Open

Use atomics instead of locking #50

nhynes opened this issue Nov 8, 2021 · 0 comments

Comments

@nhynes
Copy link
Contributor

nhynes commented Nov 8, 2021

In rpc/server.go

func (srv *Web3Gateway) Close() error {
  srv.startStopLock.Lock()
  defer srv.startStopLock.Unlock()

  srv.lock.Lock()
  state := srv.state
  srv.lock.Unlock()

implements an atomic int using a heavy mutex. Using the appropriate atomic datatype would be less surprising. This isn't in a performance critical section of code, so it's not a big issue. It's just a little linty.

But really, why is this one variable atomic? Shouldn't the entire block be protected by a mutex if there's larger global state modification going on?

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

1 participant