Skip to content

Commit b2ecd63

Browse files
committed
use RLock for tcpMutex in some places
1 parent 2c9008f commit b2ecd63

2 files changed

Lines changed: 5 additions & 5 deletions

File tree

internal/gameServer/server.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -32,7 +32,7 @@ type GameServer struct {
3232
udpListener *net.UDPConn
3333
registrations map[byte]*Registration
3434
registrationsMutex sync.Mutex
35-
tcpMutex sync.Mutex
35+
tcpMutex sync.RWMutex
3636
tcpFiles map[string][]byte
3737
customData map[byte][]byte
3838
Logger logr.Logger

internal/gameServer/tcp.go

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -44,9 +44,9 @@ func (g *GameServer) tcpSendFile(tcpData *TCPData, conn *net.TCPConn, withSize b
4444
var ok bool
4545
var data []byte
4646
for !ok {
47-
g.tcpMutex.Lock()
47+
g.tcpMutex.RLock()
4848
data, ok = g.tcpFiles[tcpData.filename]
49-
g.tcpMutex.Unlock()
49+
g.tcpMutex.RUnlock()
5050
if !ok {
5151
time.Sleep(time.Millisecond)
5252
if time.Since(startTime) > TCPTimeout {
@@ -97,9 +97,9 @@ func (g *GameServer) tcpSendCustom(conn *net.TCPConn, customID byte) {
9797
var ok bool
9898
var data []byte
9999
for !ok {
100-
g.tcpMutex.Lock()
100+
g.tcpMutex.RLock()
101101
data, ok = g.customData[customID]
102-
g.tcpMutex.Unlock()
102+
g.tcpMutex.RUnlock()
103103
if !ok {
104104
time.Sleep(time.Millisecond)
105105
if time.Since(startTime) > TCPTimeout {

0 commit comments

Comments
 (0)