mirror of
https://github.com/tailscale/tailscale.git
synced 2025-06-08 08:48:35 +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 {
|
func (r *Resource) GetFoo(ctx ctxlock.Context) string {
|
||||||
defer ctxlock.Lock(ctx, &r.mu).Unlock() // Lock the mutex if not already held.
|
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
|
return r.foo
|
||||||
}
|
}
|
||||||
|
|
||||||
func (r *Resource) SetFoo(ctx ctxlock.Context, foo string) {
|
func (r *Resource) SetFoo(ctx ctxlock.Context, foo string) {
|
||||||
defer ctxlock.Lock(ctx, &r.mu).Unlock()
|
defer ctxlock.Lock(ctx, &r.mu).Unlock()
|
||||||
syncs.AssertLocked(&r.mu)
|
|
||||||
r.foo = foo
|
r.foo = foo
|
||||||
}
|
}
|
||||||
|
|
||||||
func (r *Resource) GetBar(ctx ctxlock.Context) string {
|
func (r *Resource) GetBar(ctx ctxlock.Context) string {
|
||||||
defer ctxlock.Lock(ctx, &r.mu).Unlock()
|
defer ctxlock.Lock(ctx, &r.mu).Unlock()
|
||||||
syncs.AssertLocked(&r.mu)
|
|
||||||
return r.bar
|
return r.bar
|
||||||
}
|
}
|
||||||
|
|
||||||
func (r *Resource) SetBar(ctx ctxlock.Context, bar string) {
|
func (r *Resource) SetBar(ctx ctxlock.Context, bar string) {
|
||||||
defer ctxlock.Lock(ctx, &r.mu).Unlock()
|
defer ctxlock.Lock(ctx, &r.mu).Unlock()
|
||||||
syncs.AssertLocked(&r.mu)
|
|
||||||
r.bar = bar
|
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.
|
// Lock the mutex if not already held, and get a new context.
|
||||||
ctx = ctxlock.Lock(ctx, &r.mu)
|
ctx = ctxlock.Lock(ctx, &r.mu)
|
||||||
defer ctx.Unlock()
|
defer ctx.Unlock()
|
||||||
syncs.AssertLocked(&r.mu)
|
|
||||||
f(ctx) // Call the callback with the new context.
|
f(ctx) // Call the callback with the new context.
|
||||||
}
|
}
|
||||||
|
|
||||||
|
Loading…
x
Reference in New Issue
Block a user