From 5e956516494fef1441c3ddce017f07c6b45104b2 Mon Sep 17 00:00:00 2001 From: lidgren Date: Sun, 26 Sep 2010 13:16:09 +0000 Subject: [PATCH] NetSha.Hash made thread safe --- Lidgren.Network/NetEncryption.cs | 10 +++++++--- 1 file changed, 7 insertions(+), 3 deletions(-) diff --git a/Lidgren.Network/NetEncryption.cs b/Lidgren.Network/NetEncryption.cs index 8e004d7..65f04c5 100644 --- a/Lidgren.Network/NetEncryption.cs +++ b/Lidgren.Network/NetEncryption.cs @@ -143,12 +143,16 @@ namespace Lidgren.Network { // TODO: switch to SHA256 private static SHA1 m_sha; + private static object s_lock = new object(); public static byte[] Hash(byte[] data) { - if (m_sha == null) - m_sha = SHA1Managed.Create(); - return m_sha.ComputeHash(data); + lock (s_lock) + { + if (m_sha == null) + m_sha = SHA1Managed.Create(); + return m_sha.ComputeHash(data); + } } }