Skip to content

Commit a33e664

Browse files
committed
Simplify Session's RWMutex
The Session struct owns its lock (an RWMutex) and does not share it with any other code. It can therefore be stored in Session by value. This eliminates a layer of pointer indirection, and simplifies the code slightly. TEST=$ go test -race ./...
1 parent 4f7d97a commit a33e664

File tree

2 files changed

+1
-3
lines changed

2 files changed

+1
-3
lines changed

melody.go

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,6 @@ package melody
22

33
import (
44
"net/http"
5-
"sync"
65

76
"github.com/gorilla/websocket"
87
)
@@ -161,7 +160,6 @@ func (m *Melody) HandleRequestWithKeys(w http.ResponseWriter, r *http.Request, k
161160
outputDone: make(chan struct{}),
162161
melody: m,
163162
open: true,
164-
rwmutex: &sync.RWMutex{},
165163
}
166164

167165
m.hub.register(session)

session.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -18,7 +18,7 @@ type Session struct {
1818
outputDone chan struct{}
1919
melody *Melody
2020
open bool
21-
rwmutex *sync.RWMutex
21+
rwmutex sync.RWMutex
2222
}
2323

2424
func (s *Session) writeMessage(message envelope) {

0 commit comments

Comments
 (0)