From a8ed185c00c3c688ae939104cc0cc752a430c168 Mon Sep 17 00:00:00 2001 From: Justin Clark-Casey (justincc) Date: Wed, 7 Dec 2011 14:55:01 +0000 Subject: properly lock CapsHandlers.m_capsHandlers --- OpenSim/Capabilities/CapsHandlers.cs | 66 ++++++++++++++++++++++-------------- 1 file changed, 40 insertions(+), 26 deletions(-) (limited to 'OpenSim') diff --git a/OpenSim/Capabilities/CapsHandlers.cs b/OpenSim/Capabilities/CapsHandlers.cs index a0e9ebc..1709f46 100644 --- a/OpenSim/Capabilities/CapsHandlers.cs +++ b/OpenSim/Capabilities/CapsHandlers.cs @@ -51,11 +51,10 @@ namespace OpenSim.Framework.Capabilities /// supplied BaseHttpServer. /// /// base HTTP server - /// host name of the HTTP - /// server + /// host name of the HTTP server /// HTTP port public CapsHandlers(BaseHttpServer httpListener, string httpListenerHostname, uint httpListenerPort) - : this (httpListener,httpListenerHostname,httpListenerPort, false) + : this(httpListener,httpListenerHostname,httpListenerPort, false) { } @@ -88,44 +87,52 @@ namespace OpenSim.Framework.Capabilities /// handler to be removed public void Remove(string capsName) { - m_httpListener.RemoveStreamHandler("POST", m_capsHandlers[capsName].Path); - m_httpListener.RemoveStreamHandler("GET", m_capsHandlers[capsName].Path); - m_capsHandlers.Remove(capsName); + lock (m_capsHandlers) + { + m_httpListener.RemoveStreamHandler("POST", m_capsHandlers[capsName].Path); + m_httpListener.RemoveStreamHandler("GET", m_capsHandlers[capsName].Path); + m_capsHandlers.Remove(capsName); + } } public bool ContainsCap(string cap) { - return m_capsHandlers.ContainsKey(cap); + lock (m_capsHandlers) + return m_capsHandlers.ContainsKey(cap); } /// /// The indexer allows us to treat the CapsHandlers object /// in an intuitive dictionary like way. /// - /// + /// /// The indexer will throw an exception when you try to /// retrieve a cap handler for a cap that is not contained in /// CapsHandlers. - /// + /// public IRequestHandler this[string idx] { get { - return m_capsHandlers[idx]; + lock (m_capsHandlers) + return m_capsHandlers[idx]; } set { - if (m_capsHandlers.ContainsKey(idx)) + lock (m_capsHandlers) { - m_httpListener.RemoveStreamHandler("POST", m_capsHandlers[idx].Path); - m_capsHandlers.Remove(idx); + if (m_capsHandlers.ContainsKey(idx)) + { + m_httpListener.RemoveStreamHandler("POST", m_capsHandlers[idx].Path); + m_capsHandlers.Remove(idx); + } + + if (null == value) return; + + m_capsHandlers[idx] = value; + m_httpListener.AddStreamHandler(value); } - - if (null == value) return; - - m_capsHandlers[idx] = value; - m_httpListener.AddStreamHandler(value); } } @@ -137,9 +144,12 @@ namespace OpenSim.Framework.Capabilities { get { - string[] __keys = new string[m_capsHandlers.Keys.Count]; - m_capsHandlers.Keys.CopyTo(__keys, 0); - return __keys; + lock (m_capsHandlers) + { + string[] __keys = new string[m_capsHandlers.Keys.Count]; + m_capsHandlers.Keys.CopyTo(__keys, 0); + return __keys; + } } } @@ -157,15 +167,19 @@ namespace OpenSim.Framework.Capabilities protocol = "https://"; string baseUrl = protocol + m_httpListenerHostName + ":" + m_httpListenerPort.ToString(); - foreach (string capsName in m_capsHandlers.Keys) + + lock (m_capsHandlers) { - if (excludeSeed && "SEED" == capsName) - continue; + foreach (string capsName in m_capsHandlers.Keys) + { + if (excludeSeed && "SEED" == capsName) + continue; - caps[capsName] = baseUrl + m_capsHandlers[capsName].Path; + caps[capsName] = baseUrl + m_capsHandlers[capsName].Path; + } } return caps; } } -} +} \ No newline at end of file -- cgit v1.1