Skip to content

Commit b3acc38

Browse files
Used source generator instead.
1 parent f0c0d4c commit b3acc38

File tree

8 files changed

+23
-16
lines changed

8 files changed

+23
-16
lines changed

build-common/NHibernate.props

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,7 @@
66
<VersionPatch Condition="'$(VersionPatch)' == ''">0</VersionPatch>
77
<!-- Clear VersionSuffix for making release and set it to dev for making development builds -->
88
<VersionSuffix Condition="'$(VersionSuffix)' == ''">dev</VersionSuffix>
9-
<LangVersion Condition="'$(MSBuildProjectExtension)' != '.vbproj'">preview</LangVersion>
9+
<LangVersion Condition="'$(MSBuildProjectExtension)' != '.vbproj'">13.0</LangVersion>
1010

1111
<VersionPrefix Condition="'$(VersionPrefix)' == ''">$(NhVersion).$(VersionPatch)</VersionPrefix>
1212
<VersionSuffix Condition="'$(VersionSuffix)' != '' AND '$(BuildNumber)' != ''">$(VersionSuffix).$(BuildNumber)</VersionSuffix>

src/NHibernate/Cache/Timestamper.cs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -12,7 +12,7 @@ namespace NHibernate.Cache
1212
/// </remarks>
1313
public static class Timestamper
1414
{
15-
private static Lock lockObject = new Lock();
15+
private static Lock lockObject = LockFactory.Create();
1616

1717
// hibernate is using System.currentMilliSeconds which is calculated
1818
// from jan 1, 1970

src/NHibernate/Context/MapBasedSessionContext.cs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -10,7 +10,7 @@ public abstract class MapBasedSessionContext : CurrentSessionContext
1010
private readonly ISessionFactoryImplementor _factory;
1111

1212
// Must be static, different instances of MapBasedSessionContext may have to yield the same map.
13-
private static readonly Lock _locker = new Lock();
13+
private static readonly Lock _locker = LockFactory.Create();
1414

1515
protected MapBasedSessionContext(ISessionFactoryImplementor factory)
1616
{

src/NHibernate/NHibernate.csproj

Lines changed: 8 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -73,8 +73,14 @@
7373
<PackageReference Include="Microsoft.CSharp" Version="4.7.0" />
7474
</ItemGroup>
7575

76-
<ItemGroup Condition="!$([MSBuild]::IsTargetFrameworkCompatible('$(TargetFramework)', 'net9.0'))">
77-
<PackageReference Include="Backport.System.Threading.Lock" Version="1.1.6" />
76+
<ItemGroup>
77+
<PackageReference Include="Backport.System.Threading.Lock" Version="3.1.4">
78+
<PrivateAssets>all</PrivateAssets>
79+
<IncludeAssets>analyzers</IncludeAssets>
80+
</PackageReference>
81+
<Using Condition="$([MSBuild]::IsTargetFrameworkCompatible('$(TargetFramework)', 'net9.0'))" Alias="Lock" Include="System.Threading.Lock" />
82+
<Using Condition="!$([MSBuild]::IsTargetFrameworkCompatible('$(TargetFramework)', 'net9.0'))" Alias="Lock" Include="Backport.System.Threading.Lock" />
83+
<Using Alias="LockFactory" Include="Backport.System.Threading.LockFactory" />
7884
</ItemGroup>
7985

8086
<ItemGroup>

src/NHibernate/Stat/StatisticsImpl.cs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -9,7 +9,7 @@ namespace NHibernate.Stat
99
{
1010
public class StatisticsImpl : IStatistics, IStatisticsImplementor
1111
{
12-
private readonly Lock _syncRoot = new Lock();
12+
private readonly Lock _syncRoot = LockFactory.Create();
1313

1414
private static readonly INHibernateLogger log = NHibernateLogger.For(typeof(StatisticsImpl));
1515
private readonly ISessionFactoryImplementor sessionFactory;

src/NHibernate/Util/AsyncReaderWriterLock.cs

Lines changed: 9 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
using System;
1+
using System;
22
using System.Threading;
33
using System.Threading.Tasks;
44

@@ -9,6 +9,7 @@ namespace NHibernate.Util
99
// https://devblogs.microsoft.com/pfxteam/building-async-coordination-primitives-part-7-asyncreaderwriterlock/
1010
internal class AsyncReaderWriterLock : IDisposable, Cache.ICacheLock
1111
{
12+
private readonly Lock _writeLockLock = LockFactory.Create();
1213
private readonly SemaphoreSlim _writeLockSemaphore = new SemaphoreSlim(1, 1);
1314
private readonly SemaphoreSlim _readLockSemaphore = new SemaphoreSlim(0, 1);
1415
private readonly Releaser _writerReleaser;
@@ -48,7 +49,7 @@ public Releaser WriteLock()
4849
if (!CanEnterWriteLock(out var waitForReadLocks))
4950
{
5051
_writeLockSemaphore.Wait();
51-
lock (_writeLockSemaphore)
52+
lock (_writeLockLock)
5253
{
5354
_writersWaiting--;
5455
}
@@ -74,7 +75,7 @@ public async Task<Releaser> WriteLockAsync()
7475
if (!CanEnterWriteLock(out var waitForReadLocks))
7576
{
7677
await _writeLockSemaphore.WaitAsync().ConfigureAwait(false);
77-
lock (_writeLockSemaphore)
78+
lock (_writeLockLock)
7879
{
7980
_writersWaiting--;
8081
}
@@ -126,7 +127,7 @@ async Task<Releaser> ReadLockInternalAsync()
126127

127128
public void Dispose()
128129
{
129-
lock (_writeLockSemaphore)
130+
lock (_writeLockLock)
130131
{
131132
_writeLockSemaphore.Dispose();
132133
_readLockSemaphore.Dispose();
@@ -139,7 +140,7 @@ public void Dispose()
139140
private bool CanEnterWriteLock(out bool waitForReadLocks)
140141
{
141142
waitForReadLocks = false;
142-
lock (_writeLockSemaphore)
143+
lock (_writeLockLock)
143144
{
144145
AssertNotDisposed();
145146
if (_writeLockSemaphore.CurrentCount > 0 && _writeLockSemaphore.Wait(0))
@@ -156,7 +157,7 @@ private bool CanEnterWriteLock(out bool waitForReadLocks)
156157

157158
private void ExitWriteLock()
158159
{
159-
lock (_writeLockSemaphore)
160+
lock (_writeLockLock)
160161
{
161162
AssertNotDisposed();
162163
if (_writeLockSemaphore.CurrentCount == 1)
@@ -187,7 +188,7 @@ private void ExitWriteLock()
187188

188189
private bool CanEnterReadLock(out SemaphoreSlim waitingReadLockSemaphore)
189190
{
190-
lock (_writeLockSemaphore)
191+
lock (_writeLockLock)
191192
{
192193
AssertNotDisposed();
193194
if (_writersWaiting == 0 && _writeLockSemaphore.CurrentCount > 0)
@@ -212,7 +213,7 @@ private bool CanEnterReadLock(out SemaphoreSlim waitingReadLockSemaphore)
212213

213214
private void ExitReadLock()
214215
{
215-
lock (_writeLockSemaphore)
216+
lock (_writeLockLock)
216217
{
217218
AssertNotDisposed();
218219
if (_currentReaders == 0)

src/NHibernate/Util/SimpleMRUCache.cs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -18,7 +18,7 @@ public class SimpleMRUCache : IDeserializationCallback
1818
{
1919
private const int DefaultStrongRefCount = 128;
2020

21-
private readonly Lock _syncRoot = new Lock();
21+
private readonly Lock _syncRoot = LockFactory.Create();
2222

2323
private readonly int strongReferenceCount;
2424

src/NHibernate/Util/SoftLimitMRUCache.cs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -24,7 +24,7 @@ namespace NHibernate.Util
2424
public class SoftLimitMRUCache : IDeserializationCallback
2525
{
2626
private const int DefaultStrongRefCount = 128;
27-
private readonly Lock _syncRoot = new Lock();
27+
private readonly Lock _syncRoot = LockFactory.Create();
2828

2929
private readonly int strongReferenceCount;
3030

0 commit comments

Comments
 (0)