summary refs log tree commit diff
path: root/crypto/src/x509/X509Crl.cs
diff options
context:
space:
mode:
authorJozef Gajdos <jozef.gajdos@disig.sk>2023-02-17 07:52:10 +0100
committerPeter Dettman <peter.dettman@bouncycastle.org>2023-02-17 17:33:28 +0700
commit31bfe2eb4ca09c38801dbf6260d148abbbebbae1 (patch)
treee318def1c9c28ee4b5f0585d8b40269594d608a3 /crypto/src/x509/X509Crl.cs
parentAEAD refactoring (diff)
downloadBouncyCastle.NET-ed25519-31bfe2eb4ca09c38801dbf6260d148abbbebbae1.tar.xz
Removing unnecessary locks in X509Certificate and X509Crl
Diffstat (limited to '')
-rw-r--r--crypto/src/x509/X509Crl.cs22
1 files changed, 6 insertions, 16 deletions
diff --git a/crypto/src/x509/X509Crl.cs b/crypto/src/x509/X509Crl.cs
index 3780d277a..e47addd7a 100644
--- a/crypto/src/x509/X509Crl.cs
+++ b/crypto/src/x509/X509Crl.cs
@@ -2,7 +2,7 @@ using System;
 using System.Collections.Generic;
 using System.IO;
 using System.Text;
-
+using System.Threading;
 using Org.BouncyCastle.Asn1;
 using Org.BouncyCastle.Asn1.Utilities;
 using Org.BouncyCastle.Asn1.X509;
@@ -63,7 +63,6 @@ namespace Org.BouncyCastle.X509
 		private readonly byte[] sigAlgParams;
 		private readonly bool isIndirect;
 
-        private readonly object cacheLock = new object();
         private CachedEncoding cachedEncoding;
 
         private volatile bool hashValueSet;
@@ -450,11 +449,9 @@ namespace Org.BouncyCastle.X509
 
         private CachedEncoding GetCachedEncoding()
         {
-            lock (cacheLock)
-            {
-                if (null != cachedEncoding)
-                    return cachedEncoding;
-            }
+			CachedEncoding localCacheEncoding = cachedEncoding;
+            if (null != localCacheEncoding)
+                return localCacheEncoding;
 
             byte[] encoding = null;
             CrlException exception = null;
@@ -469,15 +466,8 @@ namespace Org.BouncyCastle.X509
 
             CachedEncoding temp = new CachedEncoding(encoding, exception);
 
-            lock (cacheLock)
-            {
-                if (null == cachedEncoding)
-                {
-                    cachedEncoding = temp;
-                }
-
-                return cachedEncoding;
-            }
+			Interlocked.CompareExchange(ref cachedEncoding, temp, null);
+            return cachedEncoding;
         }
     }
 }