Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Replace usage of obsolete Castle.Core.Internal.Lock #576

Merged
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@
</PropertyGroup>

<ItemGroup>
<PackageReference Include="Castle.Core" Version="4.3.1" />
<PackageReference Include="Castle.Core" Version="4.4.1" />
<PackageReference Include="Microsoft.AspNet.Mvc" Version="5.2.3" />
<PackageReference Include="Microsoft.Web.Infrastructure" Version="1.0.0" />
<PackageReference Include="Microsoft.NET.Test.Sdk" Version="15.3.0" />
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,7 @@
</PropertyGroup>

<ItemGroup>
<PackageReference Include="Castle.Core" Version="4.3.1" />
<PackageReference Include="Castle.Core" Version="4.4.1" />
<PackageReference Include="NUnit" Version="3.8.1" />
<PackageReference Include="NUnit3TestAdapter" Version="3.8.0" />
<PackageReference Include="Microsoft.NET.Test.Sdk" Version="15.3.0" />
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@
</PropertyGroup>

<ItemGroup>
<PackageReference Include="Castle.Core" Version="4.3.1" />
<PackageReference Include="Castle.Core" Version="4.4.1" />
<PackageReference Include="Microsoft.AspNet.WebApi" Version="5.2.3" />
<PackageReference Include="Microsoft.Web.Infrastructure" Version="1.0.0" />
<PackageReference Include="Microsoft.NET.Test.Sdk" Version="15.3.0" />
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -11,8 +11,8 @@
</PropertyGroup>

<ItemGroup>
<PackageReference Include="Castle.Core" Version="4.3.1" />
<PackageReference Include="Castle.Core-log4net" Version="4.3.1" />
<PackageReference Include="Castle.Core" Version="4.4.1" />
<PackageReference Include="Castle.Core-log4net" Version="4.4.1" />
</ItemGroup>

<ItemGroup>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -12,8 +12,8 @@
</PropertyGroup>

<ItemGroup>
<PackageReference Include="Castle.Core" Version="4.3.1" />
<PackageReference Include="Castle.Core-log4net" Version="4.3.1" />
<PackageReference Include="Castle.Core" Version="4.4.1" />
<PackageReference Include="Castle.Core-log4net" Version="4.4.1" />
<PackageReference Include="Microsoft.NET.Test.Sdk" Version="15.3.0" />
<PackageReference Include="Microsoft.TestPlatform.ObjectModel" Version="11.0.0" />
<PackageReference Include="NUnit" Version="3.8.1" />
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,8 @@ namespace Castle.Facilities.WcfIntegration
{
using System;
using System.ServiceModel.Discovery;
using Castle.Core.Internal;

using Castle.MicroKernel.Internal;

public class DiscoveryProxyCache : DiscoveryEndpointProvider, IDisposable
{
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -22,8 +22,9 @@ namespace Castle.Facilities.WcfIntegration
using System.ServiceModel;
using System.ServiceModel.Channels;
using System.Threading;
using Castle.Core.Internal;

using Castle.Facilities.WcfIntegration.Internal;
using Castle.MicroKernel.Internal;

public class WcfChannelHolder : IWcfChannelHolder
{
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,8 @@ namespace Castle.Facilities.WcfIntegration
using System;
using System.Collections.Generic;
using System.ServiceModel.Discovery;
using Castle.Core.Internal;

using Castle.MicroKernel.Internal;

public delegate bool PolicyMembership(EndpointDiscoveryMetadata endpoint);

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -14,16 +14,16 @@

namespace Castle.Facilities.WcfIntegration
{
using System;
using System.Collections.Generic;
using System.Linq;
using System.ServiceModel;
using System.ServiceModel.Discovery;

using Castle.Core;
using Castle.Core.Internal;
using System;
using Castle.MicroKernel.Internal;

public class InMemoryServiceCatalog : IServiceCatalogImplementation
public class InMemoryServiceCatalog : IServiceCatalogImplementation
{
private readonly List<ILoadBalancePolicy> policies;
private readonly ILoadBalancePolicyFactory policyFactory;
Expand Down
6 changes: 3 additions & 3 deletions src/Castle.Windsor.Tests/Castle.Windsor.Tests.csproj
Original file line number Diff line number Diff line change
Expand Up @@ -50,9 +50,9 @@
</ItemGroup>

<ItemGroup Condition="'$(TargetFramework)'=='net45'">
<PackageReference Include="Castle.Core" Version="4.3.1" />
<PackageReference Include="Castle.Core-log4net" Version="4.3.1" />
<PackageReference Include="Castle.Core-NLog" Version="4.3.1" />
<PackageReference Include="Castle.Core" Version="4.4.1" />
<PackageReference Include="Castle.Core-log4net" Version="4.4.1" />
<PackageReference Include="Castle.Core-NLog" Version="4.4.1" />
<PackageReference Include="Microsoft.TestPlatform.ObjectModel" Version="11.0.0" />
</ItemGroup>

Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,187 @@
// Copyright 2004-2010 Castle Project - http://www.castleproject.org/
//
// Licensed under the Apache License, Version 2.0 (the "License");
// you may not use this file except in compliance with the License.
// You may obtain a copy of the License at
//
// http://www.apache.org/licenses/LICENSE-2.0
//
// Unless required by applicable law or agreed to in writing, software
// distributed under the License is distributed on an "AS IS" BASIS,
// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
// See the License for the specific language governing permissions and
// limitations under the License.

namespace CastleTests.MicroKernel.Internal
{
using System.Threading;

using Castle.MicroKernel.Internal;

using NUnit.Framework;

[TestFixture]
public class SlimReadWriteLockTestCase
{
private SlimReadWriteLock @lock;

[SetUp]
public void SetUp()
{
@lock = new SlimReadWriteLock();
}

[Test]
public void Can_be_used_ForReading_multiple_nested_time()
{
using (@lock.ForReading())
{
using (@lock.ForReading())
{
Assert.IsTrue(@lock.IsReadLockHeld);
}
Assert.IsTrue(@lock.IsReadLockHeld);
}
}

[Test]
public void Can_be_used_ForWriting_multiple_nested_time()
{
using (@lock.ForWriting())
{
using (@lock.ForWriting())
{
Assert.IsTrue(@lock.IsWriteLockHeld);
}
Assert.IsTrue(@lock.IsWriteLockHeld);
}
}

[Test]
public void Can_be_used_ForReadingUpgradeable_multiple_nested_time()
{
using (@lock.ForReadingUpgradeable())
{
using (@lock.ForReadingUpgradeable())
{
Assert.IsTrue(@lock.IsUpgradeableReadLockHeld);
}
Assert.IsTrue(@lock.IsUpgradeableReadLockHeld);
}
}

[Test]
public void Can_be_upgraded_from_nested_ForReadingUpgradeable()
{
using (@lock.ForReadingUpgradeable())
{
using (var holder = @lock.ForReadingUpgradeable())
{
holder.Upgrade();
Assert.IsTrue(@lock.IsWriteLockHeld);
}
}
}

[Test]
public void Can_be_used_ForReading_when_used_ForWriting()
{
using (@lock.ForWriting())
{
using (var holder = @lock.ForReading())
{
Assert.IsTrue(@lock.IsWriteLockHeld);
Assert.IsTrue(holder.LockAcquired);
}
}
}

[Test]
public void Can_be_used_ForReading_when_used_ForReadingUpgradeable()
{
using (@lock.ForReadingUpgradeable())
{
using (var holder = @lock.ForReading())
{
Assert.IsTrue(@lock.IsUpgradeableReadLockHeld);
Assert.IsTrue(holder.LockAcquired);
}
}
}

[Test]
public void Can_NOT_be_used_ForReadingUpgradeable_when_used_ForReading()
{
using (@lock.ForReading())
{
Assert.Throws(typeof(LockRecursionException), () => @lock.ForReadingUpgradeable());
}
}

[Test]
public void Can_be_used_ForReadingUpgradeable_when_used_ForWriting()
{
using (@lock.ForWriting())
{
using (var holder = @lock.ForReadingUpgradeable())
{
Assert.IsTrue(@lock.IsWriteLockHeld);
Assert.IsTrue(holder.LockAcquired);
}
}
}

[Test]
public void Can_NOT_be_used_ForWriting_when_used_ForReading()
{
using (@lock.ForReading())
{
Assert.Throws(typeof(LockRecursionException), () => @lock.ForWriting());
}
}

[Test]
public void Can_be_used_ForWriting_when_used_ForReadingUpgradeable()
{
using (@lock.ForReadingUpgradeable())
{
using (var holder = @lock.ForWriting())
{
Assert.IsTrue(@lock.IsUpgradeableReadLockHeld);
Assert.IsTrue(holder.LockAcquired);
}
Assert.IsTrue(@lock.IsUpgradeableReadLockHeld);
}
}

[Test]
public void Can_be_used_ForWriting_when_used_ForReadingUpgradeable_and_upgraded_after()
{
using (var upg = @lock.ForReadingUpgradeable())
{
using (var holder = @lock.ForWriting())
{
Assert.IsTrue(@lock.IsUpgradeableReadLockHeld);
Assert.IsTrue(holder.LockAcquired);
upg.Upgrade();
}
Assert.IsTrue(@lock.IsUpgradeableReadLockHeld);
}
}

[Test]
public void Can_be_used_ForWriting_when_used_ForReadingUpgradeable_and_upgraded_before()
{
using (var upg = @lock.ForReadingUpgradeable())
{
upg.Upgrade();
using (var holder = @lock.ForWriting())
{
Assert.IsTrue(@lock.IsUpgradeableReadLockHeld);
Assert.IsTrue(holder.LockAcquired);
}
Assert.IsTrue(@lock.IsUpgradeableReadLockHeld);
}
}
}
}
2 changes: 1 addition & 1 deletion src/Castle.Windsor/Castle.Windsor.csproj
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,7 @@
</ItemGroup>

<ItemGroup>
<PackageReference Include="Castle.Core" Version="4.3.1" />
<PackageReference Include="Castle.Core" Version="4.4.1" />
</ItemGroup>

<ItemGroup Condition="'$(TargetFramework)'=='net45'">
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@ namespace Castle.Core.Internal
public class SimpleThreadSafeCollection<T>
{
private readonly List<T> implementation = new List<T>();
private readonly Lock @lock = Lock.Create();
private readonly MicroKernel.Internal.Lock @lock =MicroKernel.Internal.Lock.Create();

public int Count
{
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,7 @@ namespace Castle.Core.Internal
using System;
using System.Collections.Generic;
using System.Linq;

generik0 marked this conversation as resolved.
Show resolved Hide resolved
/// <summary>
/// Simple type for thread safe adding/reading to/from keyed store. The difference between this and built in concurrent dictionary is that in this case adding is happening under a lock so never more than one thread will be adding at a time.
/// </summary>
Expand All @@ -26,7 +26,7 @@ namespace Castle.Core.Internal
public class SimpleThreadSafeDictionary<TKey, TValue>
{
private readonly Dictionary<TKey, TValue> inner = new Dictionary<TKey, TValue>();
private readonly Lock @lock = Lock.Create();
private readonly MicroKernel.Internal.Lock @lock = MicroKernel.Internal.Lock.Create();

public bool Contains(TKey key)
{
Expand Down
4 changes: 2 additions & 2 deletions src/Castle.Windsor/Core/Internal/SimpleThreadSafeSet.cs
Original file line number Diff line number Diff line change
Expand Up @@ -15,11 +15,11 @@
namespace Castle.Core.Internal
{
using System.Collections.Generic;

public class SimpleThreadSafeSet<T>
{
private readonly HashSet<T> implementation = new HashSet<T>();
private readonly Lock @lock = Lock.Create();
private readonly MicroKernel.Internal.Lock @lock = MicroKernel.Internal.Lock.Create();

public int Count
{
Expand Down
23 changes: 23 additions & 0 deletions src/Castle.Windsor/MicroKernel/Internal/ILockHolder.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,23 @@
// Copyright 2004-2009 Castle Project - http://www.castleproject.org/
//
// Licensed under the Apache License, Version 2.0 (the "License");
// you may not use this file except in compliance with the License.
// You may obtain a copy of the License at
//
// http://www.apache.org/licenses/LICENSE-2.0
//
// Unless required by applicable law or agreed to in writing, software
// distributed under the License is distributed on an "AS IS" BASIS,
// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
// See the License for the specific language governing permissions and
// limitations under the License.

namespace Castle.MicroKernel.Internal
{
using System;

public interface ILockHolder : IDisposable
{
bool LockAcquired { get; }
}
}
Loading