milvus/pkg/util/syncutil/closed_lock.go
Zhen Ye 2ec6e602d6
enhance: add streaming client metrics (#36523)
issue: #33285

---------

Signed-off-by: chyezh <chyezh@outlook.com>
2024-10-08 21:25:19 +08:00

28 lines
353 B
Go

package syncutil
import "sync"
type ClosableLock struct {
mu sync.Mutex
closed bool
}
func (l *ClosableLock) LockIfNotClosed() bool {
l.mu.Lock()
if l.closed {
l.mu.Unlock()
return false
}
return true
}
func (l *ClosableLock) Unlock() {
l.mu.Unlock()
}
func (l *ClosableLock) Close() {
l.mu.Lock()
l.closed = true
l.mu.Unlock()
}