Skip to content
This repository was archived by the owner on Aug 30, 2023. It is now read-only.

Commit adb5dff

Browse files
morikunimattrobenolt
morikuni
authored andcommitted
Use pointer type for right use of mutex
1 parent d1aab6e commit adb5dff

File tree

2 files changed

+4
-4
lines changed

2 files changed

+4
-4
lines changed

stacktrace.go

+2-2
Original file line numberDiff line numberDiff line change
@@ -195,7 +195,7 @@ type SourceCodeLoader interface {
195195
Load(filename string, line, context int) ([][]byte, int)
196196
}
197197

198-
var sourceCodeLoader SourceCodeLoader = fsLoader{cache: make(map[string][][]byte)}
198+
var sourceCodeLoader SourceCodeLoader = &fsLoader{cache: make(map[string][][]byte)}
199199

200200
func SetSourceCodeLoader(loader SourceCodeLoader) {
201201
sourceCodeLoader = loader
@@ -206,7 +206,7 @@ type fsLoader struct {
206206
cache map[string][][]byte
207207
}
208208

209-
func (fs fsLoader) Load(filename string, line, context int) ([][]byte, int) {
209+
func (fs *fsLoader) Load(filename string, line, context int) ([][]byte, int) {
210210
fs.mu.Lock()
211211
defer fs.mu.Unlock()
212212
lines, ok := fs.cache[filename]

stacktrace_test.go

+2-2
Original file line numberDiff line numberDiff line change
@@ -169,7 +169,7 @@ func TestNewStacktrace_noFrames(t *testing.T) {
169169

170170
func TestFileContext(t *testing.T) {
171171
// reset the cache
172-
sourceCodeLoader = fsLoader{cache: make(map[string][][]byte)}
172+
sourceCodeLoader = &fsLoader{cache: make(map[string][][]byte)}
173173

174174
tempdir, err := ioutil.TempDir("", "")
175175
if err != nil {
@@ -205,7 +205,7 @@ func TestFileContext(t *testing.T) {
205205
t.Errorf("%d: fileContext(%#v, 1, 0) = %v, %v; expected len()=%d, %d",
206206
i, test.path, lines, index, test.expectedLines, test.expectedIndex)
207207
}
208-
cacheLen := len(sourceCodeLoader.(fsLoader).cache)
208+
cacheLen := len(sourceCodeLoader.(*fsLoader).cache)
209209
if cacheLen != i+1 {
210210
t.Errorf("%d: result was not cached; len=%d", i, cacheLen)
211211
}

0 commit comments

Comments
 (0)