diff options
author | Luke Shumaker <lukeshu@lukeshu.com> | 2023-02-28 14:05:27 -0700 |
---|---|---|
committer | Luke Shumaker <lukeshu@lukeshu.com> | 2023-03-14 19:45:07 -0600 |
commit | 8c8c6c27552f8554ba014c34d684cb90538ef65b (patch) | |
tree | f3a53ed194e29b516b52770e4949a1e508fad6a7 /lib/btrfsprogs/btrfsinspect/rebuildnodes/btrees/nestedlock.go | |
parent | 34bf167ef33c57b4d6767273f1d265971a4693b9 (diff) |
Move files around [ci-skip]
Diffstat (limited to 'lib/btrfsprogs/btrfsinspect/rebuildnodes/btrees/nestedlock.go')
-rw-r--r-- | lib/btrfsprogs/btrfsinspect/rebuildnodes/btrees/nestedlock.go | 45 |
1 files changed, 0 insertions, 45 deletions
diff --git a/lib/btrfsprogs/btrfsinspect/rebuildnodes/btrees/nestedlock.go b/lib/btrfsprogs/btrfsinspect/rebuildnodes/btrees/nestedlock.go deleted file mode 100644 index c1ffa18..0000000 --- a/lib/btrfsprogs/btrfsinspect/rebuildnodes/btrees/nestedlock.go +++ /dev/null @@ -1,45 +0,0 @@ -// Copyright (C) 2023 Luke Shumaker <lukeshu@lukeshu.com> -// -// SPDX-License-Identifier: GPL-2.0-or-later - -package btrees - -import ( - "context" - "sync" -) - -// A nestedMutex is like a sync.Mutex, but while it is locked by call -// 'A', may be simultaneously locked by subsequent calls if the -// subsequent calls use a Context descended from the one returned by -// the 'A' call to .Lock(). -type nestedMutex struct { - inner sync.Mutex - depth int -} - -type nestedMutexCtxKey struct{} - -// Lock locks the mutex. It is invalid to use a Context returned from -// Lock in a different goroutine than the one it was created in. It -// is invalid to use a Context returned from Lock after the mutex has -// subsequently become unlocked. -func (m *nestedMutex) Lock(ctx context.Context) context.Context { - if other, ok := ctx.Value(nestedMutexCtxKey{}).(*nestedMutex); ok && other == m { - m.depth++ - return ctx - } - m.inner.Lock() - return context.WithValue(ctx, nestedMutexCtxKey{}, m) -} - -// Unlock unlocks the mutex. It is invalid to call Unlock if the -// mutex is not already locked. It is invalid to call Unlock from -// multiple goroutines simultaneously. -func (m *nestedMutex) Unlock() { - if m.depth > 0 { - m.depth-- - } else { - m.inner.Unlock() - } -} |