File tree 1 file changed +6
-6
lines changed
websites/code2/studygolang/src/logic
1 file changed +6
-6
lines changed Original file line number Diff line number Diff line change @@ -59,20 +59,20 @@ func (this *UserData) MessageQueue(serverId int) chan *Message {
59
59
}
60
60
61
61
func (this * UserData ) Remove (serverId int ) {
62
- this .rwMutex .RLock ()
63
- defer this .rwMutex .RUnlock ()
62
+ this .rwMutex .Lock ()
63
+ defer this .rwMutex .Unlock ()
64
64
delete (this .serverMsgQueue , serverId )
65
65
}
66
66
67
67
func (this * UserData ) InitMessageQueue (serverId int ) {
68
68
this .rwMutex .Lock ()
69
69
defer this .rwMutex .Unlock ()
70
- this .serverMsgQueue [serverId ] = make (chan * Message , 1 )
70
+ this .serverMsgQueue [serverId ] = make (chan * Message , 4 )
71
71
}
72
72
73
73
func (this * UserData ) SendMessage (message * Message ) {
74
- this .rwMutex .Lock ()
75
- defer this .rwMutex .Unlock ()
74
+ this .rwMutex .RLock ()
75
+ defer this .rwMutex .RUnlock ()
76
76
77
77
for _ , messageQueue := range this .serverMsgQueue {
78
78
messageQueue <- message
@@ -100,7 +100,7 @@ func (this *book) AddUser(user, serverId int) *UserData {
100
100
userData .lastAccessTime = time .Now ()
101
101
} else {
102
102
userData = & UserData {
103
- serverMsgQueue : map [int ]chan * Message {serverId : make (chan * Message , 1 )},
103
+ serverMsgQueue : map [int ]chan * Message {serverId : make (chan * Message , 4 )},
104
104
lastAccessTime : time .Now (),
105
105
}
106
106
this .users [user ] = userData
You can’t perform that action at this time.
0 commit comments