Skip to content
Projects
Groups
Snippets
Help
Loading...
Help
Support
Keyboard shortcuts
?
Submit feedback
Contribute to GitLab
Sign in / Register
Toggle navigation
G
go
Project overview
Project overview
Details
Activity
Releases
Repository
Repository
Files
Commits
Branches
Tags
Contributors
Graph
Compare
Issues
0
Issues
0
List
Boards
Labels
Milestones
Merge Requests
0
Merge Requests
0
Analytics
Analytics
Repository
Value Stream
Wiki
Wiki
Snippets
Snippets
Members
Members
Collapse sidebar
Close sidebar
Activity
Graph
Create a new issue
Commits
Issue Boards
Open sidebar
Kirill Smelkov
go
Commits
63e383cf
Commit
63e383cf
authored
Mar 06, 2012
by
David Symonds
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
expvar: add locking to String, and use RWMutex properly throughout.
R=bradfitz CC=golang-dev
https://golang.org/cl/5754043
parent
5e46a8c9
Changes
1
Hide whitespace changes
Inline
Side-by-side
Showing
1 changed file
with
18 additions
and
9 deletions
+18
-9
src/pkg/expvar/expvar.go
src/pkg/expvar/expvar.go
+18
-9
No files found.
src/pkg/expvar/expvar.go
View file @
63e383cf
...
...
@@ -41,12 +41,12 @@ type Var interface {
// Int is a 64-bit integer variable that satisfies the Var interface.
type
Int
struct
{
i
int64
mu
sync
.
Mutex
mu
sync
.
RW
Mutex
}
func
(
v
*
Int
)
String
()
string
{
v
.
mu
.
Lock
()
defer
v
.
mu
.
Unlock
()
v
.
mu
.
R
Lock
()
defer
v
.
mu
.
R
Unlock
()
return
strconv
.
FormatInt
(
v
.
i
,
10
)
}
...
...
@@ -65,12 +65,12 @@ func (v *Int) Set(value int64) {
// Float is a 64-bit float variable that satisfies the Var interface.
type
Float
struct
{
f
float64
mu
sync
.
Mutex
mu
sync
.
RW
Mutex
}
func
(
v
*
Float
)
String
()
string
{
v
.
mu
.
Lock
()
defer
v
.
mu
.
Unlock
()
v
.
mu
.
R
Lock
()
defer
v
.
mu
.
R
Unlock
()
return
strconv
.
FormatFloat
(
v
.
f
,
'g'
,
-
1
,
64
)
}
...
...
@@ -188,12 +188,21 @@ func (v *Map) Do(f func(KeyValue)) {
// String is a string variable, and satisfies the Var interface.
type
String
struct
{
s
string
s
string
mu
sync
.
RWMutex
}
func
(
v
*
String
)
String
()
string
{
return
strconv
.
Quote
(
v
.
s
)
}
func
(
v
*
String
)
String
()
string
{
v
.
mu
.
RLock
()
defer
v
.
mu
.
RUnlock
()
return
strconv
.
Quote
(
v
.
s
)
}
func
(
v
*
String
)
Set
(
value
string
)
{
v
.
s
=
value
}
func
(
v
*
String
)
Set
(
value
string
)
{
v
.
mu
.
Lock
()
defer
v
.
mu
.
Unlock
()
v
.
s
=
value
}
// Func implements Var by calling the function
// and formatting the returned value using JSON.
...
...
Write
Preview
Markdown
is supported
0%
Try again
or
attach a new file
Attach a file
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Cancel
Please
register
or
sign in
to comment