内置方法普通加锁
This commit is contained in:
parent
ac4276544d
commit
a9768f5aa3
15
easylock/abstruct.go
Normal file
15
easylock/abstruct.go
Normal file
@ -0,0 +1,15 @@
|
||||
// Package easylock...
|
||||
//
|
||||
// Description : easylock...
|
||||
//
|
||||
// Author : go_developer@163.com<张德满>
|
||||
//
|
||||
// Date : 2021-02-24 6:29 下午
|
||||
package easylock
|
||||
|
||||
type EasyLock interface {
|
||||
Lock() error
|
||||
Unlock() error
|
||||
RLock() error
|
||||
RUnlock() error
|
||||
}
|
40
easylock/lock.go
Normal file
40
easylock/lock.go
Normal file
@ -0,0 +1,40 @@
|
||||
// Package easylock...
|
||||
//
|
||||
// Description : 包装各种姿势的锁
|
||||
//
|
||||
// Author : go_developer@163.com<张德满>
|
||||
//
|
||||
// Date : 2021-02-24 6:26 下午
|
||||
package easylock
|
||||
|
||||
import "sync"
|
||||
|
||||
func NewLock() EasyLock {
|
||||
return &lock{
|
||||
sc: &sync.RWMutex{},
|
||||
}
|
||||
}
|
||||
|
||||
type lock struct {
|
||||
sc *sync.RWMutex
|
||||
}
|
||||
|
||||
func (l *lock) Lock() error {
|
||||
l.sc.Lock()
|
||||
return nil
|
||||
}
|
||||
|
||||
func (l *lock) Unlock() error {
|
||||
l.sc.Unlock()
|
||||
return nil
|
||||
}
|
||||
|
||||
func (l *lock) RLock() error {
|
||||
l.sc.RLock()
|
||||
return nil
|
||||
}
|
||||
|
||||
func (l *lock) RUnlock() error {
|
||||
l.sc.Unlock()
|
||||
return nil
|
||||
}
|
Loading…
Reference in New Issue
Block a user