mirror of
https://github.com/tailscale/tailscale.git
synced 2025-06-07 16:28:37 +00:00
util/ctxlock: remove AssertLocked usage from the example
Updates #12614 Signed-off-by: Nick Khyl <nickk@tailscale.com>
This commit is contained in:
parent
a414b760a2
commit
7df612309e
@ -18,25 +18,21 @@ type Resource struct {
|
||||
|
||||
func (r *Resource) GetFoo(ctx ctxlock.Context) string {
|
||||
defer ctxlock.Lock(ctx, &r.mu).Unlock() // Lock the mutex if not already held.
|
||||
syncs.AssertLocked(&r.mu) // Panic if mu is still unlocked.
|
||||
return r.foo
|
||||
}
|
||||
|
||||
func (r *Resource) SetFoo(ctx ctxlock.Context, foo string) {
|
||||
defer ctxlock.Lock(ctx, &r.mu).Unlock()
|
||||
syncs.AssertLocked(&r.mu)
|
||||
r.foo = foo
|
||||
}
|
||||
|
||||
func (r *Resource) GetBar(ctx ctxlock.Context) string {
|
||||
defer ctxlock.Lock(ctx, &r.mu).Unlock()
|
||||
syncs.AssertLocked(&r.mu)
|
||||
return r.bar
|
||||
}
|
||||
|
||||
func (r *Resource) SetBar(ctx ctxlock.Context, bar string) {
|
||||
defer ctxlock.Lock(ctx, &r.mu).Unlock()
|
||||
syncs.AssertLocked(&r.mu)
|
||||
r.bar = bar
|
||||
}
|
||||
|
||||
@ -44,7 +40,6 @@ func (r *Resource) WithLock(ctx ctxlock.Context, f func(ctx ctxlock.Context)) {
|
||||
// Lock the mutex if not already held, and get a new context.
|
||||
ctx = ctxlock.Lock(ctx, &r.mu)
|
||||
defer ctx.Unlock()
|
||||
syncs.AssertLocked(&r.mu)
|
||||
f(ctx) // Call the callback with the new context.
|
||||
}
|
||||
|
||||
|
Loading…
x
Reference in New Issue
Block a user