diff options
| author | Evan Jones <evan.jones@bluecore.com> | 2019-09-03 20:09:28 +0000 |
|---|---|---|
| committer | Brad Fitzpatrick <bradfitz@golang.org> | 2019-12-04 02:50:12 +0000 |
| commit | 2e616b842c1127f0f4f1e49fcf2765d347bcaea1 (patch) | |
| tree | e5353ca89cd810368f60014fc40523ddd7e0ef8a | |
| parent | 6bb846ce41cdca087b14c8e3560a679691c424b6 (diff) | |
| download | golang-id-tour-2e616b842c1127f0f4f1e49fcf2765d347bcaea1.tar.xz | |
tour: Rename mux -> mu to follow convention
Nearly all sync.Mutex members in the standard library are named mu,
or use "mu" as part of the name. While this isn't a documented
recommendation anywhere that I can find, it would seem nice to start
new users with this same convention.
Change-Id: I67cbe2a0052b81d8bb57d5ece0cefd2f3838f298
GitHub-Last-Rev: 31ef869d9b72e7eb08b9be9340242b0e535a175f
GitHub-Pull-Request: golang/tour#813
Reviewed-on: https://go-review.googlesource.com/c/tour/+/192725
Reviewed-by: Brad Fitzpatrick <bradfitz@golang.org>
| -rw-r--r-- | content/concurrency/mutex-counter.go | 12 |
1 files changed, 6 insertions, 6 deletions
diff --git a/content/concurrency/mutex-counter.go b/content/concurrency/mutex-counter.go index ed727bd..b1483d6 100644 --- a/content/concurrency/mutex-counter.go +++ b/content/concurrency/mutex-counter.go @@ -10,23 +10,23 @@ import ( // SafeCounter is safe to use concurrently. type SafeCounter struct { - v map[string]int - mux sync.Mutex + mu sync.Mutex + v map[string]int } // Inc increments the counter for the given key. func (c *SafeCounter) Inc(key string) { - c.mux.Lock() + c.mu.Lock() // Lock so only one goroutine at a time can access the map c.v. c.v[key]++ - c.mux.Unlock() + c.mu.Unlock() } // Value returns the current value of the counter for the given key. func (c *SafeCounter) Value(key string) int { - c.mux.Lock() + c.mu.Lock() // Lock so only one goroutine at a time can access the map c.v. - defer c.mux.Unlock() + defer c.mu.Unlock() return c.v[key] } |
