make lock methods private

This commit is contained in:
vyzo 2019-05-17 23:41:05 +03:00
parent 28b1a9f31d
commit 07ee3fb062

View File

@ -20,25 +20,25 @@ func NewProtoBook(meta pstore.PeerMetadata) pstore.ProtoBook {
return &dsProtoBook{meta: meta} return &dsProtoBook{meta: meta}
} }
func (pb *dsProtoBook) Lock(p peer.ID) { func (pb *dsProtoBook) lock(p peer.ID) {
pb.lks[byte(p[len(p)-1])].Lock() pb.lks[byte(p[len(p)-1])].Lock()
} }
func (pb *dsProtoBook) Unlock(p peer.ID) { func (pb *dsProtoBook) unlock(p peer.ID) {
pb.lks[byte(p[len(p)-1])].Unlock() pb.lks[byte(p[len(p)-1])].Unlock()
} }
func (pb *dsProtoBook) RLock(p peer.ID) { func (pb *dsProtoBook) rlock(p peer.ID) {
pb.lks[byte(p[len(p)-1])].RLock() pb.lks[byte(p[len(p)-1])].RLock()
} }
func (pb *dsProtoBook) RUnlock(p peer.ID) { func (pb *dsProtoBook) runlock(p peer.ID) {
pb.lks[byte(p[len(p)-1])].RUnlock() pb.lks[byte(p[len(p)-1])].RUnlock()
} }
func (pb *dsProtoBook) SetProtocols(p peer.ID, protos ...string) error { func (pb *dsProtoBook) SetProtocols(p peer.ID, protos ...string) error {
pb.Lock(p) pb.lock(p)
defer pb.Unlock(p) defer pb.unlock(p)
protomap := make(map[string]struct{}, len(protos)) protomap := make(map[string]struct{}, len(protos))
for _, proto := range protos { for _, proto := range protos {
@ -49,8 +49,8 @@ func (pb *dsProtoBook) SetProtocols(p peer.ID, protos ...string) error {
} }
func (pb *dsProtoBook) AddProtocols(p peer.ID, protos ...string) error { func (pb *dsProtoBook) AddProtocols(p peer.ID, protos ...string) error {
pb.Lock(p) pb.lock(p)
defer pb.Unlock(p) defer pb.unlock(p)
pmap, err := pb.getProtocolMap(p) pmap, err := pb.getProtocolMap(p)
if err != nil { if err != nil {
@ -65,8 +65,8 @@ func (pb *dsProtoBook) AddProtocols(p peer.ID, protos ...string) error {
} }
func (pb *dsProtoBook) GetProtocols(p peer.ID) ([]string, error) { func (pb *dsProtoBook) GetProtocols(p peer.ID) ([]string, error) {
pb.RLock(p) pb.rlock(p)
defer pb.RUnlock(p) defer pb.runlock(p)
pmap, err := pb.getProtocolMap(p) pmap, err := pb.getProtocolMap(p)
if err != nil { if err != nil {
@ -82,8 +82,8 @@ func (pb *dsProtoBook) GetProtocols(p peer.ID) ([]string, error) {
} }
func (pb *dsProtoBook) SupportsProtocols(p peer.ID, protos ...string) ([]string, error) { func (pb *dsProtoBook) SupportsProtocols(p peer.ID, protos ...string) ([]string, error) {
pb.RLock(p) pb.rlock(p)
defer pb.RUnlock(p) defer pb.runlock(p)
pmap, err := pb.getProtocolMap(p) pmap, err := pb.getProtocolMap(p)
if err != nil { if err != nil {