sync for backup
This commit is contained in:
parent
b3db20785b
commit
f6878107d8
1 changed files with 30 additions and 0 deletions
30
wrapped-mutex/mutex.go
Normal file
30
wrapped-mutex/mutex.go
Normal file
|
@ -0,0 +1,30 @@
|
||||||
|
package wrappedmutex
|
||||||
|
|
||||||
|
import "sync"
|
||||||
|
|
||||||
|
type Mutex[T any] struct {
|
||||||
|
wrapped T
|
||||||
|
lock sync.Mutex
|
||||||
|
}
|
||||||
|
|
||||||
|
func New[T any](wrapped T) Mutex[T] {
|
||||||
|
return Mutex[T]{
|
||||||
|
wrapped: wrapped,
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
func (m *Mutex[T]) Lock() {
|
||||||
|
m.lock.Lock()
|
||||||
|
}
|
||||||
|
|
||||||
|
func (m *Mutex[T]) TryLock() bool {
|
||||||
|
return m.lock.TryLock()
|
||||||
|
}
|
||||||
|
|
||||||
|
func (m *Mutex[T]) Unlock() {
|
||||||
|
m.lock.Unlock()
|
||||||
|
}
|
||||||
|
|
||||||
|
func (m *Mutex[T]) Get() *T {
|
||||||
|
return &m.wrapped
|
||||||
|
}
|
Loading…
Reference in a new issue