Fix locking #212

Merged
merged 6 commits into from Dec 3, 2015

Conversation

Projects
None yet
4 participants
Contributor

zyga commented Dec 2, 2015

No description provided.

zyga added some commits Dec 2, 2015

Add caps.Repository.hasType()
Signed-off-by: Zygmunt Krynicki <zygmunt.krynicki@canonical.com>
Implement caps.Repository.HasType() with hasType()
Signed-off-by: Zygmunt Krynicki <zygmunt.krynicki@canonical.com>
Use hasType() when already holding the lock
Signed-off-by: Zygmunt Krynicki <zygmunt.krynicki@canonical.com>
Add locking to caps.Repository.HasType()
Signed-off-by: Zygmunt Krynicki <zygmunt.krynicki@canonical.com>
caps/repo.go
@@ -81,6 +81,14 @@ func (r *Repository) HasType(t *Type) bool {
return false
}
+// HasType checks if the repository contains the given type.
@chipaca

chipaca Dec 2, 2015

Member

checks whether, not if.

@zyga

zyga Dec 2, 2015

Contributor

Noted, I'll fix this in the next round. I have a few more Foo() == foo() + locking methods in the pipe

@zyga

zyga Dec 3, 2015

Contributor

Fixed

Member

chipaca commented Dec 2, 2015

👍

caps/repo.go
@@ -71,8 +71,8 @@ func (r *Repository) Add(cap *Capability) error {
return nil
}
-// HasType checks if the repository contains the given type.
-func (r *Repository) HasType(t *Type) bool {
+// hasType is identical to HasType but doesn't hold the repository lock
@niemeyer

niemeyer Dec 2, 2015

Contributor

And you expect we, wannabe robots, to never mistype h by H or the opposite on every context? :-)

This should be named unlockedHasType or something. Or, alternatively, can we get rid of the public version altogether? I can't see many practical public use cases for a full-type comparison like this.

@zyga

zyga Dec 3, 2015

Contributor

+1 on unlockedFoo when there's a need for having both. I'll kill the public version in this case as you are right it is not really needed.

Contributor

niemeyer commented Dec 3, 2015

Still pending an answer to whether we can drop the public version, or whether we should rename it.

zyga added some commits Dec 3, 2015

Remove caps.HasType(), keeping hasType()
Signed-off-by: Zygmunt Krynicki <zygmunt.krynicki@canonical.com>
Tweak comment on caps.Repository.hasType
Signed-off-by: Zygmunt Krynicki <zygmunt.krynicki@canonical.com>
Collaborator

mvo5 commented Dec 3, 2015

Sorry, I'm late to the party and now I'm confused. The branch says "adds locking" but I do not see locking anymore in the diff? Is github lying to me? Or did something else change here?

Contributor

zyga commented Dec 3, 2015

The branch evolved to the point where loccking is gone as the only remaining method is private and you are expected to call it from public methods that already take the lock

Collaborator

mvo5 commented Dec 3, 2015

Thanks, in this case +1 from me

chipaca added a commit that referenced this pull request Dec 3, 2015

@chipaca chipaca merged commit 5cf0281 into snapcore:master Dec 3, 2015

2 checks passed

continuous-integration/travis-ci/pr The Travis CI build passed
Details
coverage/coveralls Coverage decreased (-0.02%) to 66.542%
Details

@zyga zyga deleted the zyga:fix-locking branch Dec 3, 2015

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment