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
|
||||
SteamClient *steam.Client
|
||||
SentryFile string
|
||||
friendSteamId map[string]*StatusSteamFriend
|
||||
friendSteamId *FriendSteam
|
||||
SteamConnecting bool
|
||||
Deleting bool
|
||||
|
||||
|
|
@ -37,7 +37,10 @@ type GatewayInfo struct {
|
|||
XMPP_IQ_RemoteRoster_Request map[string]string
|
||||
AllowEditRoster bool
|
||||
ChatstateNotificationData chan string
|
||||
}
|
||||
|
||||
type FriendSteam struct {
|
||||
steamId map[string]*StatusSteamFriend
|
||||
sync.RWMutex
|
||||
}
|
||||
|
||||
|
|
@ -74,22 +77,22 @@ func (g *GatewayInfo) Delete() {
|
|||
}
|
||||
|
||||
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 {
|
||||
s.RLock()
|
||||
defer s.RUnlock()
|
||||
return s.friendSteamId[steamId]
|
||||
s.friendSteamId.RLock()
|
||||
defer s.friendSteamId.RUnlock()
|
||||
return s.friendSteamId.steamId[steamId]
|
||||
}
|
||||
|
||||
func (s *GatewayInfo) GetAllFriendSteamId() []string {
|
||||
s.RLock()
|
||||
defer s.RUnlock()
|
||||
allSteamIds := make([]string, len(s.friendSteamId))
|
||||
s.friendSteamId.RLock()
|
||||
defer s.friendSteamId.RUnlock()
|
||||
allSteamIds := make([]string, len(s.friendSteamId.steamId))
|
||||
|
||||
i := 0
|
||||
for steamId := range s.friendSteamId {
|
||||
for steamId := range s.friendSteamId.steamId {
|
||||
allSteamIds[i] = steamId
|
||||
i++
|
||||
}
|
||||
|
|
@ -97,13 +100,13 @@ func (s *GatewayInfo) GetAllFriendSteamId() []string {
|
|||
}
|
||||
|
||||
func (s *GatewayInfo) SetFriendSteamId(steamId string, status *StatusSteamFriend) {
|
||||
s.Lock()
|
||||
s.friendSteamId[steamId] = status
|
||||
s.Unlock()
|
||||
s.friendSteamId.Lock()
|
||||
s.friendSteamId.steamId[steamId] = status
|
||||
s.friendSteamId.Unlock()
|
||||
}
|
||||
|
||||
func (s *GatewayInfo) RemoveFriendSteamId(steamId string) {
|
||||
s.Lock()
|
||||
delete(s.friendSteamId, steamId)
|
||||
s.Unlock()
|
||||
s.friendSteamId.Lock()
|
||||
delete(s.friendSteamId.steamId, steamId)
|
||||
s.friendSteamId.Unlock()
|
||||
}
|
||||
|
|
|
|||
Loading…
Reference in New Issue