diff options
author | UbitUmarov | 2016-11-09 20:09:49 +0000 |
---|---|---|
committer | UbitUmarov | 2016-11-09 20:09:49 +0000 |
commit | 1e1d0d8204181e4dedf438332625941cd56b02c2 (patch) | |
tree | 3c54eb1d721d1a2b030fa599396869f1e6f8da91 /OpenSim/Region/CoreModules/ServiceConnectorsOut | |
parent | minor cleanup (diff) | |
download | opensim-SC_OLD-1e1d0d8204181e4dedf438332625941cd56b02c2.zip opensim-SC_OLD-1e1d0d8204181e4dedf438332625941cd56b02c2.tar.gz opensim-SC_OLD-1e1d0d8204181e4dedf438332625941cd56b02c2.tar.bz2 opensim-SC_OLD-1e1d0d8204181e4dedf438332625941cd56b02c2.tar.xz |
move UserAccountCache access locking to its methods and not callers.
Diffstat (limited to 'OpenSim/Region/CoreModules/ServiceConnectorsOut')
3 files changed, 54 insertions, 55 deletions
diff --git a/OpenSim/Region/CoreModules/ServiceConnectorsOut/UserAccounts/LocalUserAccountServiceConnector.cs b/OpenSim/Region/CoreModules/ServiceConnectorsOut/UserAccounts/LocalUserAccountServiceConnector.cs index 3127199..a413a8b 100644 --- a/OpenSim/Region/CoreModules/ServiceConnectorsOut/UserAccounts/LocalUserAccountServiceConnector.cs +++ b/OpenSim/Region/CoreModules/ServiceConnectorsOut/UserAccounts/LocalUserAccountServiceConnector.cs | |||
@@ -154,14 +154,12 @@ namespace OpenSim.Region.CoreModules.ServiceConnectorsOut.UserAccounts | |||
154 | { | 154 | { |
155 | bool inCache = false; | 155 | bool inCache = false; |
156 | UserAccount account; | 156 | UserAccount account; |
157 | lock(m_Cache) | 157 | account = m_Cache.Get(userID, out inCache); |
158 | account = m_Cache.Get(userID, out inCache); | ||
159 | if (inCache) | 158 | if (inCache) |
160 | return account; | 159 | return account; |
161 | 160 | ||
162 | account = UserAccountService.GetUserAccount(scopeID, userID); | 161 | account = UserAccountService.GetUserAccount(scopeID, userID); |
163 | lock(m_Cache) | 162 | m_Cache.Cache(userID, account); |
164 | m_Cache.Cache(userID, account); | ||
165 | 163 | ||
166 | return account; | 164 | return account; |
167 | } | 165 | } |
@@ -170,15 +168,13 @@ namespace OpenSim.Region.CoreModules.ServiceConnectorsOut.UserAccounts | |||
170 | { | 168 | { |
171 | bool inCache = false; | 169 | bool inCache = false; |
172 | UserAccount account; | 170 | UserAccount account; |
173 | lock(m_Cache) | 171 | account = m_Cache.Get(firstName + " " + lastName, out inCache); |
174 | account = m_Cache.Get(firstName + " " + lastName, out inCache); | ||
175 | if (inCache) | 172 | if (inCache) |
176 | return account; | 173 | return account; |
177 | 174 | ||
178 | account = UserAccountService.GetUserAccount(scopeID, firstName, lastName); | 175 | account = UserAccountService.GetUserAccount(scopeID, firstName, lastName); |
179 | if (account != null) | 176 | if (account != null) |
180 | lock(m_Cache) | 177 | m_Cache.Cache(account.PrincipalID, account); |
181 | m_Cache.Cache(account.PrincipalID, account); | ||
182 | 178 | ||
183 | return account; | 179 | return account; |
184 | } | 180 | } |
@@ -201,8 +197,7 @@ namespace OpenSim.Region.CoreModules.ServiceConnectorsOut.UserAccounts | |||
201 | { | 197 | { |
202 | if(UUID.TryParse(id, out uuid)) | 198 | if(UUID.TryParse(id, out uuid)) |
203 | { | 199 | { |
204 | lock(m_Cache) | 200 | account = m_Cache.Get(uuid, out inCache); |
205 | account = m_Cache.Get(uuid, out inCache); | ||
206 | if (inCache) | 201 | if (inCache) |
207 | ret.Add(account); | 202 | ret.Add(account); |
208 | else | 203 | else |
@@ -220,8 +215,7 @@ namespace OpenSim.Region.CoreModules.ServiceConnectorsOut.UserAccounts | |||
220 | foreach(UserAccount acc in ext) | 215 | foreach(UserAccount acc in ext) |
221 | { | 216 | { |
222 | if(acc != null) | 217 | if(acc != null) |
223 | lock(m_Cache) | 218 | m_Cache.Cache(acc.PrincipalID, acc); |
224 | m_Cache.Cache(acc.PrincipalID, acc); | ||
225 | } | 219 | } |
226 | } | 220 | } |
227 | return ret; | 221 | return ret; |
diff --git a/OpenSim/Region/CoreModules/ServiceConnectorsOut/UserAccounts/RemoteUserAccountServiceConnector.cs b/OpenSim/Region/CoreModules/ServiceConnectorsOut/UserAccounts/RemoteUserAccountServiceConnector.cs index 9140d78..60dd97a 100644 --- a/OpenSim/Region/CoreModules/ServiceConnectorsOut/UserAccounts/RemoteUserAccountServiceConnector.cs +++ b/OpenSim/Region/CoreModules/ServiceConnectorsOut/UserAccounts/RemoteUserAccountServiceConnector.cs | |||
@@ -128,8 +128,7 @@ namespace OpenSim.Region.CoreModules.ServiceConnectorsOut.UserAccounts | |||
128 | // flags, title, etc. And country, don't forget country! | 128 | // flags, title, etc. And country, don't forget country! |
129 | private void OnNewClient(IClientAPI client) | 129 | private void OnNewClient(IClientAPI client) |
130 | { | 130 | { |
131 | lock(m_Cache) | 131 | m_Cache.Remove(client.Name); |
132 | m_Cache.Remove(client.Name); | ||
133 | } | 132 | } |
134 | 133 | ||
135 | #region Overwritten methods from IUserAccountService | 134 | #region Overwritten methods from IUserAccountService |
@@ -138,17 +137,14 @@ namespace OpenSim.Region.CoreModules.ServiceConnectorsOut.UserAccounts | |||
138 | { | 137 | { |
139 | bool inCache = false; | 138 | bool inCache = false; |
140 | UserAccount account; | 139 | UserAccount account; |
141 | lock(m_Cache) | 140 | account = m_Cache.Get(userID, out inCache); |
142 | account = m_Cache.Get(userID, out inCache); | ||
143 | if (inCache) | 141 | if (inCache) |
144 | return account; | 142 | return account; |
145 | 143 | ||
146 | account = base.GetUserAccount(scopeID, userID); | 144 | account = base.GetUserAccount(scopeID, userID); |
147 | if(account != null) | 145 | if(account != null) |
148 | { | 146 | m_Cache.Cache(userID, account); |
149 | lock(m_Cache) | 147 | |
150 | m_Cache.Cache(userID, account); | ||
151 | } | ||
152 | return account; | 148 | return account; |
153 | } | 149 | } |
154 | 150 | ||
@@ -156,17 +152,14 @@ namespace OpenSim.Region.CoreModules.ServiceConnectorsOut.UserAccounts | |||
156 | { | 152 | { |
157 | bool inCache = false; | 153 | bool inCache = false; |
158 | UserAccount account; | 154 | UserAccount account; |
159 | lock(m_Cache) | 155 | account = m_Cache.Get(firstName + " " + lastName, out inCache); |
160 | account = m_Cache.Get(firstName + " " + lastName, out inCache); | ||
161 | if (inCache) | 156 | if (inCache) |
162 | return account; | 157 | return account; |
163 | 158 | ||
164 | account = base.GetUserAccount(scopeID, firstName, lastName); | 159 | account = base.GetUserAccount(scopeID, firstName, lastName); |
165 | if (account != null) | 160 | if (account != null) |
166 | { | 161 | m_Cache.Cache(account.PrincipalID, account); |
167 | lock(m_Cache) | 162 | |
168 | m_Cache.Cache(account.PrincipalID, account); | ||
169 | } | ||
170 | return account; | 163 | return account; |
171 | } | 164 | } |
172 | 165 | ||
@@ -183,8 +176,7 @@ namespace OpenSim.Region.CoreModules.ServiceConnectorsOut.UserAccounts | |||
183 | { | 176 | { |
184 | if(UUID.TryParse(id, out uuid)) | 177 | if(UUID.TryParse(id, out uuid)) |
185 | { | 178 | { |
186 | lock(m_Cache) | 179 | account = m_Cache.Get(uuid, out inCache); |
187 | account = m_Cache.Get(uuid, out inCache); | ||
188 | if (inCache) | 180 | if (inCache) |
189 | accs.Add(account); | 181 | accs.Add(account); |
190 | else | 182 | else |
@@ -202,8 +194,7 @@ namespace OpenSim.Region.CoreModules.ServiceConnectorsOut.UserAccounts | |||
202 | if(acc != null) | 194 | if(acc != null) |
203 | { | 195 | { |
204 | accs.Add(acc); | 196 | accs.Add(acc); |
205 | lock(m_Cache) | 197 | m_Cache.Cache(acc.PrincipalID, acc); |
206 | m_Cache.Cache(acc.PrincipalID, acc); | ||
207 | } | 198 | } |
208 | } | 199 | } |
209 | } | 200 | } |
diff --git a/OpenSim/Region/CoreModules/ServiceConnectorsOut/UserAccounts/UserAccountCache.cs b/OpenSim/Region/CoreModules/ServiceConnectorsOut/UserAccounts/UserAccountCache.cs index 53610d9..97baf87 100644 --- a/OpenSim/Region/CoreModules/ServiceConnectorsOut/UserAccounts/UserAccountCache.cs +++ b/OpenSim/Region/CoreModules/ServiceConnectorsOut/UserAccounts/UserAccountCache.cs | |||
@@ -44,6 +44,7 @@ namespace OpenSim.Region.CoreModules.ServiceConnectorsOut.UserAccounts | |||
44 | 44 | ||
45 | private ExpiringCache<UUID, UserAccount> m_UUIDCache; | 45 | private ExpiringCache<UUID, UserAccount> m_UUIDCache; |
46 | private ExpiringCache<string, UUID> m_NameCache; | 46 | private ExpiringCache<string, UUID> m_NameCache; |
47 | private object accessLock = new object(); | ||
47 | 48 | ||
48 | public UserAccountCache() | 49 | public UserAccountCache() |
49 | { | 50 | { |
@@ -54,60 +55,73 @@ namespace OpenSim.Region.CoreModules.ServiceConnectorsOut.UserAccounts | |||
54 | public void Cache(UUID userID, UserAccount account) | 55 | public void Cache(UUID userID, UserAccount account) |
55 | { | 56 | { |
56 | // Cache even null accounts | 57 | // Cache even null accounts |
57 | m_UUIDCache.AddOrUpdate(userID, account, CACHE_EXPIRATION_SECONDS); | 58 | lock(accessLock) |
58 | if (account != null) | 59 | { |
59 | m_NameCache.AddOrUpdate(account.Name, account.PrincipalID, CACHE_EXPIRATION_SECONDS); | 60 | m_UUIDCache.AddOrUpdate(userID, account, CACHE_EXPIRATION_SECONDS); |
61 | if (account != null) | ||
62 | m_NameCache.AddOrUpdate(account.Name, account.PrincipalID, CACHE_EXPIRATION_SECONDS); | ||
60 | 63 | ||
61 | //m_log.DebugFormat("[USER CACHE]: cached user {0}", userID); | 64 | //m_log.DebugFormat("[USER CACHE]: cached user {0}", userID); |
65 | } | ||
62 | } | 66 | } |
63 | 67 | ||
64 | public void Invalidate(UUID userID) | 68 | public void Invalidate(UUID userID) |
65 | { | 69 | { |
66 | m_UUIDCache.Remove(userID); | 70 | lock(accessLock) |
71 | m_UUIDCache.Remove(userID); | ||
67 | } | 72 | } |
68 | 73 | ||
69 | public UserAccount Get(UUID userID, out bool inCache) | 74 | public UserAccount Get(UUID userID, out bool inCache) |
70 | { | 75 | { |
71 | UserAccount account = null; | 76 | UserAccount account = null; |
72 | inCache = false; | 77 | inCache = false; |
73 | if (m_UUIDCache.TryGetValue(userID, out account)) | 78 | lock(accessLock) |
74 | { | 79 | { |
75 | //m_log.DebugFormat("[USER CACHE]: Account {0} {1} found in cache", account.FirstName, account.LastName); | 80 | if (m_UUIDCache.TryGetValue(userID, out account)) |
76 | inCache = true; | 81 | { |
77 | return account; | 82 | //m_log.DebugFormat("[USER CACHE]: Account {0} {1} found in cache", account.FirstName, account.LastName); |
83 | inCache = true; | ||
84 | return account; | ||
85 | } | ||
78 | } | 86 | } |
79 | |||
80 | return null; | 87 | return null; |
81 | } | 88 | } |
82 | 89 | ||
83 | public UserAccount Get(string name, out bool inCache) | 90 | public UserAccount Get(string name, out bool inCache) |
84 | { | 91 | { |
85 | inCache = false; | 92 | inCache = false; |
86 | if (!m_NameCache.Contains(name)) | 93 | lock(accessLock) |
87 | return null; | 94 | { |
95 | if (!m_NameCache.Contains(name)) | ||
96 | return null; | ||
88 | 97 | ||
89 | UserAccount account = null; | 98 | UserAccount account = null; |
90 | UUID uuid = UUID.Zero; | 99 | UUID uuid = UUID.Zero; |
91 | if (m_NameCache.TryGetValue(name, out uuid)) | 100 | if (m_NameCache.TryGetValue(name, out uuid)) |
92 | if (m_UUIDCache.TryGetValue(uuid, out account)) | ||
93 | { | 101 | { |
94 | inCache = true; | 102 | if (m_UUIDCache.TryGetValue(uuid, out account)) |
95 | return account; | 103 | { |
104 | inCache = true; | ||
105 | return account; | ||
106 | } | ||
96 | } | 107 | } |
97 | 108 | } | |
98 | return null; | 109 | return null; |
99 | } | 110 | } |
100 | 111 | ||
101 | public void Remove(string name) | 112 | public void Remove(string name) |
102 | { | 113 | { |
103 | if (!m_NameCache.Contains(name)) | 114 | lock(accessLock) |
104 | return; | ||
105 | |||
106 | UUID uuid = UUID.Zero; | ||
107 | if (m_NameCache.TryGetValue(name, out uuid)) | ||
108 | { | 115 | { |
109 | m_NameCache.Remove(name); | 116 | if (!m_NameCache.Contains(name)) |
110 | m_UUIDCache.Remove(uuid); | 117 | return; |
118 | |||
119 | UUID uuid = UUID.Zero; | ||
120 | if (m_NameCache.TryGetValue(name, out uuid)) | ||
121 | { | ||
122 | m_NameCache.Remove(name); | ||
123 | m_UUIDCache.Remove(uuid); | ||
124 | } | ||
111 | } | 125 | } |
112 | } | 126 | } |
113 | } | 127 | } |