Better concurrent map read/write management for friend steam id map.
This commit is contained in:
parent
4961ad8c9e
commit
458b96bffb
|
|
@ -25,7 +25,7 @@ type GatewayInfo struct {
|
||||||
SteamLoginInfo *steam.LogOnDetails
|
SteamLoginInfo *steam.LogOnDetails
|
||||||
SteamClient *steam.Client
|
SteamClient *steam.Client
|
||||||
SentryFile string
|
SentryFile string
|
||||||
friendSteamId map[string]*StatusSteamFriend
|
friendSteamId *FriendSteam
|
||||||
SteamConnecting bool
|
SteamConnecting bool
|
||||||
Deleting bool
|
Deleting bool
|
||||||
|
|
||||||
|
|
@ -37,7 +37,10 @@ type GatewayInfo struct {
|
||||||
XMPP_IQ_RemoteRoster_Request map[string]string
|
XMPP_IQ_RemoteRoster_Request map[string]string
|
||||||
AllowEditRoster bool
|
AllowEditRoster bool
|
||||||
ChatstateNotificationData chan string
|
ChatstateNotificationData chan string
|
||||||
|
}
|
||||||
|
|
||||||
|
type FriendSteam struct {
|
||||||
|
steamId map[string]*StatusSteamFriend
|
||||||
sync.RWMutex
|
sync.RWMutex
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
@ -74,22 +77,22 @@ func (g *GatewayInfo) Delete() {
|
||||||
}
|
}
|
||||||
|
|
||||||
func (s *GatewayInfo) CreateSteamIds() {
|
func (s *GatewayInfo) CreateSteamIds() {
|
||||||
s.friendSteamId = make(map[string]*StatusSteamFriend)
|
s.friendSteamId = &FriendSteam{steamId: make(map[string]*StatusSteamFriend)}
|
||||||
}
|
}
|
||||||
|
|
||||||
func (s *GatewayInfo) GetFriendSteamId(steamId string) *StatusSteamFriend {
|
func (s *GatewayInfo) GetFriendSteamId(steamId string) *StatusSteamFriend {
|
||||||
s.RLock()
|
s.friendSteamId.RLock()
|
||||||
defer s.RUnlock()
|
defer s.friendSteamId.RUnlock()
|
||||||
return s.friendSteamId[steamId]
|
return s.friendSteamId.steamId[steamId]
|
||||||
}
|
}
|
||||||
|
|
||||||
func (s *GatewayInfo) GetAllFriendSteamId() []string {
|
func (s *GatewayInfo) GetAllFriendSteamId() []string {
|
||||||
s.RLock()
|
s.friendSteamId.RLock()
|
||||||
defer s.RUnlock()
|
defer s.friendSteamId.RUnlock()
|
||||||
allSteamIds := make([]string, len(s.friendSteamId))
|
allSteamIds := make([]string, len(s.friendSteamId.steamId))
|
||||||
|
|
||||||
i := 0
|
i := 0
|
||||||
for steamId := range s.friendSteamId {
|
for steamId := range s.friendSteamId.steamId {
|
||||||
allSteamIds[i] = steamId
|
allSteamIds[i] = steamId
|
||||||
i++
|
i++
|
||||||
}
|
}
|
||||||
|
|
@ -97,13 +100,13 @@ func (s *GatewayInfo) GetAllFriendSteamId() []string {
|
||||||
}
|
}
|
||||||
|
|
||||||
func (s *GatewayInfo) SetFriendSteamId(steamId string, status *StatusSteamFriend) {
|
func (s *GatewayInfo) SetFriendSteamId(steamId string, status *StatusSteamFriend) {
|
||||||
s.Lock()
|
s.friendSteamId.Lock()
|
||||||
s.friendSteamId[steamId] = status
|
s.friendSteamId.steamId[steamId] = status
|
||||||
s.Unlock()
|
s.friendSteamId.Unlock()
|
||||||
}
|
}
|
||||||
|
|
||||||
func (s *GatewayInfo) RemoveFriendSteamId(steamId string) {
|
func (s *GatewayInfo) RemoveFriendSteamId(steamId string) {
|
||||||
s.Lock()
|
s.friendSteamId.Lock()
|
||||||
delete(s.friendSteamId, steamId)
|
delete(s.friendSteamId.steamId, steamId)
|
||||||
s.Unlock()
|
s.friendSteamId.Unlock()
|
||||||
}
|
}
|
||||||
|
|
|
||||||
Loading…
Reference in New Issue