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

libs: Make bitarray functions lock parameters that aren't the caller #2081

Merged
merged 1 commit into from Jul 27, 2018

Conversation

ValarDragon
Copy link
Contributor

This now makes bit array functions which take in a second bit array, thread
safe. Previously there was a warning on bitarray.Update to be lock the
second parameter externally if thread safety wasrequired.
This was not done within the codebase, so it was fine to change here.

Closes #2080

  • Updated all relevant documentation in docs - is there any? Updated the relevant godocs
  • Updated all code comments where relevant
  • Wrote tests - n/a
  • Updated CHANGELOG.md

This now makes bit array functions which take in a second bit array, thread
safe. Previously there was a warning on bitarray.Update to be lock the
second parameter externally if thread safety wasrequired.
This was not done within the codebase, so it was fine to change here.

Closes #2080
@ValarDragon ValarDragon added this to Ongoing in current iteration via automation Jul 27, 2018
@ValarDragon ValarDragon moved this from Ongoing to Review Needed in current iteration Jul 27, 2018
@codecov-io
Copy link

Codecov Report

Merging #2081 into develop will decrease coverage by 0.1%.
The diff coverage is 93.33%.

@@             Coverage Diff             @@
##           develop    #2081      +/-   ##
===========================================
- Coverage    62.75%   62.65%   -0.11%     
===========================================
  Files          215      215              
  Lines        17277    17344      +67     
===========================================
+ Hits         10843    10867      +24     
- Misses        5546     5591      +45     
+ Partials       888      886       -2
Impacted Files Coverage Δ
libs/common/bit_array.go 79.88% <93.33%> (+1.15%) ⬆️
types/test_util.go 69.23% <0%> (-9.72%) ⬇️
libs/common/async.go 88.4% <0%> (-2.9%) ⬇️
lite/inquiring_certifier.go 71.42% <0%> (-1.71%) ⬇️
p2p/conn/connection.go 81.97% <0%> (-0.29%) ⬇️
p2p/peer.go 60.22% <0%> (ø) ⬆️
libs/db/remotedb/grpcdb/server.go 0% <0%> (ø) ⬆️
consensus/reactor.go 78.74% <0%> (+0.26%) ⬆️
types/validator_set.go 67.52% <0%> (+3.14%) ⬆️
... and 1 more

@xla xla added this to the launch milestone Jul 27, 2018
@xla xla self-assigned this Jul 27, 2018
@xla xla added C:libs Component: Library T:enhancement Type: Enhancement labels Jul 27, 2018
current iteration automation moved this from Review Needed to Reviewed Jul 27, 2018
Copy link
Contributor

@xla xla left a comment

Choose a reason for hiding this comment

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

👍 :octocat: :shipit: 🍡

As commented inline would not do the bundled defer, for ease of editing and clarity of lifecycle.

defer func() {
bA.mtx.Unlock()
o.mtx.Unlock()
}()
Copy link
Contributor

Choose a reason for hiding this comment

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

Why not:

a.mtx.Lock()
defer a.mtx.Unlock()
o.mtx.Lock
defer o.mtx.Unlock

Copy link
Contributor Author

Choose a reason for hiding this comment

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

The reason I didn't bundle the defers is because my understanding is that each defer call is kinda slow: golang/go#14939

Do you think the performance should matter here? Its a bit of a micro-performance tweak, and its not at all clear that it applies here, so I'd be happy to switch to the more easy to maintain version :)

Copy link
Contributor

Choose a reason for hiding this comment

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

As it is to be expected that BitArray might be used in tight loops this is a valid concern.

defer func() {
bA.mtx.Unlock()
o.mtx.Unlock()
}()
Copy link
Contributor

Choose a reason for hiding this comment

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

Same as above

@xla xla merged commit bc526f1 into develop Jul 27, 2018
current iteration automation moved this from Reviewed to Done Jul 27, 2018
@xla xla deleted the dev/mtx_2_param_bit_array_funcs branch July 27, 2018 02:21
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
C:libs Component: Library T:enhancement Type: Enhancement
Projects
No open projects
Development

Successfully merging this pull request may close these issues.

None yet

3 participants