diff options
author | Jozef Gajdos <jozef.gajdos@disig.sk> | 2023-02-17 07:52:10 +0100 |
---|---|---|
committer | Peter Dettman <peter.dettman@bouncycastle.org> | 2023-02-17 17:33:28 +0700 |
commit | 31bfe2eb4ca09c38801dbf6260d148abbbebbae1 (patch) | |
tree | e318def1c9c28ee4b5f0585d8b40269594d608a3 /crypto/src/x509/X509Crl.cs | |
parent | AEAD refactoring (diff) | |
download | BouncyCastle.NET-ed25519-31bfe2eb4ca09c38801dbf6260d148abbbebbae1.tar.xz |
Removing unnecessary locks in X509Certificate and X509Crl
Diffstat (limited to '')
-rw-r--r-- | crypto/src/x509/X509Crl.cs | 22 |
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; } } } |