From f6878107d80438e5240f14f9792eb32cc694f0a9 Mon Sep 17 00:00:00 2001 From: mStar Date: Thu, 22 Aug 2024 19:56:37 +0200 Subject: [PATCH] sync for backup --- wrapped-mutex/mutex.go | 30 ++++++++++++++++++++++++++++++ 1 file changed, 30 insertions(+) create mode 100644 wrapped-mutex/mutex.go diff --git a/wrapped-mutex/mutex.go b/wrapped-mutex/mutex.go new file mode 100644 index 0000000..6563842 --- /dev/null +++ b/wrapped-mutex/mutex.go @@ -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 +}