Skip to content

Commit

Permalink
init with atomic and semaphore lock
Browse files Browse the repository at this point in the history
  • Loading branch information
David Hock committed Nov 15, 2024
1 parent bbf059f commit dcefc74
Show file tree
Hide file tree
Showing 48 changed files with 2,185 additions and 33 deletions.
47 changes: 47 additions & 0 deletions .editorconfig
Original file line number Diff line number Diff line change
Expand Up @@ -170,3 +170,50 @@ indent_size = 2
end_of_line = lf
[*.{cmd,bat}]
end_of_line = crlf

####################################
# Override .NET Coding Conventions #
####################################
[*.cs]

# this. preferences
dotnet_style_qualification_for_field = false:none
dotnet_style_qualification_for_property = false:none
dotnet_style_qualification_for_method = false:none
dotnet_style_qualification_for_event = false:none

# Expression-bodied members
csharp_style_expression_bodied_constructors = true:suggestion


# public static fields using PascalCase
dotnet_naming_rule.static_fields_should_have_pascal_case.severity = suggestion
dotnet_naming_rule.static_fields_should_have_pascal_case.symbols = public_static_fields
dotnet_naming_rule.static_fields_should_have_pascal_case.style = pascal_case_style

dotnet_naming_symbols.public_static_fields.applicable_kinds = field
dotnet_naming_symbols.public_static_fields.required_modifiers = static
dotnet_naming_symbols.public_static_fields.applicable_accessibilities = public

dotnet_naming_style.pascal_case_style.capitalization = pascal_case

# internal and private fields should be _camelCase
dotnet_naming_rule.camel_case_for_private_internal_fields.severity = suggestion
dotnet_naming_rule.camel_case_for_private_internal_fields.symbols = private_internal_fields
dotnet_naming_rule.camel_case_for_private_internal_fields.style = camel_case_underscore_style
dotnet_naming_symbols.private_internal_fields.applicable_kinds = field
dotnet_naming_symbols.private_internal_fields.applicable_accessibilities = private, internal
dotnet_naming_style.camel_case_underscore_style.required_prefix = _
dotnet_naming_style.camel_case_underscore_style.capitalization = camel_case

# internal and private static fields should have _PascalCase
dotnet_naming_rule.private_internal_static_fields_should_have_prefix.severity = suggestion
dotnet_naming_rule.private_internal_static_fields_should_have_prefix.symbols = private_internal_static_fields
dotnet_naming_rule.private_internal_static_fields_should_have_prefix.style = pascal_case_underscore_style

dotnet_naming_symbols.private_internal_static_fields.applicable_kinds = field
dotnet_naming_symbols.private_internal_static_fields.required_modifiers = static, const
dotnet_naming_symbols.private_internal_static_fields.applicable_accessibilities = private, internal

dotnet_naming_style.pascal_case_underscore_style.required_prefix = _
dotnet_naming_style.pascal_case_underscore_style.capitalization = pascal_case
75 changes: 75 additions & 0 deletions .github/workflows/build-and-test.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,75 @@
name: build

on:
push:
branches:
- main
- releases/*
tags:
- releases/*

pull_request:
branches:
- main

jobs:
build:
name: Build ${{ matrix.display-name }}
runs-on: ubuntu-latest
strategy:
fail-fast: false
matrix:
configuration: ['debug', 'release']
include:
- configuration: 'debug'
display-name: 'Debug'
- configuration: 'release'
display-name: 'Release'
steps:
- uses: actions/checkout@v1

- name: Setup .NET
uses: actions/setup-dotnet@v1
with:
dotnet-version: 9.0.x

- name: Build
run: dotnet build --configuration ${{ matrix.configuration }}

test:
name: Test ${{ matrix.display-name }}
runs-on: ubuntu-latest
strategy:
fail-fast: false
matrix:
dotnet-version: ['8.0', '9.0']
include:
- dotnet-version: '8.0'
display-name: '.NET 8.0'
framework: 'net8'
prefix: 'net8'
install-version: '8.0.x'
- dotnet-version: '9.0'
display-name: '.NET 9.0'
framework: 'net9'
prefix: 'net9'
install-version: '9.0.x'
steps:
- uses: actions/checkout@v1

- name: Setup ${{ matrix.display-name }}
uses: actions/setup-dotnet@v1
with:
dotnet-version: ${{ matrix.install-version }}
- name: Setup .NET 9.0
uses: actions/setup-dotnet@v1
if: ${{ matrix.install-version != '9.0.x' }}
with:
dotnet-version: 9.0.x

- name: Test
id: tests
continue-on-error: true # proceed if tests fail to allow for the report generation in master or next step failure in PR
run: |
dotnet test \
--framework ${{ matrix.framework }} \
27 changes: 27 additions & 0 deletions AdHoc.Locking.slnx
Original file line number Diff line number Diff line change
@@ -0,0 +1,27 @@
<Solution>
<Properties Name="Visual Studio">
<Property Name="OpenWith" Value="17" />
</Properties>
<Folder Name="/.Settings/">
<File Path=".editorconfig" />
<File Path=".gitignore" />
<File Path="Directory.Build.props" />
<File Path="Directory.Build.targets" />
<File Path="Directory.Packages.props" />
<File Path="global.json" />
<File Path="NuGet.config" />
<File Path=".gitattributes" />
</Folder>
<Project Path="src\AdHoc.Locking.Abstraction\AdHoc.Locking.Abstraction.csproj" />
<Project Path="src\AdHoc.Locking.Extensions.DependencyInjection\AdHoc.Locking.Extensions.DependencyInjection.csproj" />
<Project Path="src\AdHoc.Locking\AdHoc.Locking.csproj" />
<Project Path="test\AdHoc.Locking.Test\AdHoc.Locking.Test.csproj" />
<Folder Name="/test/">
<Project Path="..\..\..\..\..\..\..\..\AdHoc\AdHoc.Locking\test\AdHoc.Locking.AtomicFileLock\AdHoc.Locking.AtomicFileLock.csproj" />
<Project Path="..\..\..\..\..\..\..\..\AdHoc\AdHoc.Locking\test\AdHoc.Locking.Test\AdHoc.Locking.Test.csproj" />
<Project Path="test\AdHoc.Locking.AtomicFileLock\AdHoc.Locking.AtomicFileLock.csproj" />
</Folder>
<Project Path="..\..\..\..\..\..\..\..\AdHoc\AdHoc.Locking\src\AdHoc.Locking.Abstraction\AdHoc.Locking.Abstraction.csproj" />
<Project Path="..\..\..\..\..\..\..\..\AdHoc\AdHoc.Locking\src\AdHoc.Locking.Extensions.DependencyInjection\AdHoc.Locking.Extensions.DependencyInjection.csproj" />
<Project Path="..\..\..\..\..\..\..\..\AdHoc\AdHoc.Locking\src\AdHoc.Locking\AdHoc.Locking.csproj" />
</Solution>
23 changes: 13 additions & 10 deletions Directory.Build.props
Original file line number Diff line number Diff line change
@@ -1,11 +1,11 @@
<Project>

<PropertyGroup>
<RepoRoot>$([System.IO.Directory]::GetParent($(MSBuildThisFileDirectory)).Parent.FullName)</RepoRoot>
<RepoRoot>$([System.IO.Path]::GetFullPath($(MSBuildThisFileDirectory)))</RepoRoot>
</PropertyGroup>

<PropertyGroup>
<TargetFramework>net9;net8</TargetFramework>
<TargetFrameworks>net9.0;net8.0</TargetFrameworks>
<LangVersion>preview</LangVersion>
<ImplicitUsings>enable</ImplicitUsings>
<Nullable>enable</Nullable>
Expand All @@ -16,21 +16,24 @@
<RepositoryType>git</RepositoryType>
<RepositoryUrl>https://github.com/Ad-Hoc-org/.dotnet</RepositoryUrl>
<PackageTags>AdHoc</PackageTags>
<PackageIcon>icon.png</PackageIcon>
<!-- <PackageIcon>icon-512.png</PackageIcon> -->
<Authors>AdHoc Authors</Authors>
<Company>AdHoc</Company>
<Copyright>Copyright AdHoc Authors</Copyright>
<IncludeSymbols>true</IncludeSymbols>
<SymbolPackageFormat>snupkg</SymbolPackageFormat>
<PackageLicenseExpression>MIT</PackageLicenseExpression>
<PackageRequireLicenseAcceptance>true</PackageRequireLicenseAcceptance>
<PackagePrimaryLicenseFile>$(RepoRoot)\LICENSE</PackagePrimaryLicenseFile>
<PackageThirdPartyNoticesFile>$(RepoRoot)\THIRD-PARTY-NOTICES.TXT</PackageThirdPartyNoticesFile>
<PackageReadmeFile>README.md</PackageReadmeFile>
<PackageChangelogFile>CHANGELOG.md</PackageChangelogFile>
<PackageReleaseNotesFile>$(RepoRoot)\RELEASENOTES.md</PackageReleaseNotesFile>
<!-- <PackagePrimaryLicenseFile>$(RepoRoot)LICENSE</PackagePrimaryLicenseFile> -->
<!-- <PackageThirdPartyNoticesFile>$(RepoRoot)THIRD-PARTY-NOTICES.TXT</PackageThirdPartyNoticesFile> -->
<!-- <PackageReadmeFile>README.md</PackageReadmeFile> -->
<!-- <PackageChangelogFile>CHANGELOG.md</PackageChangelogFile> -->
<!-- <PackageReleaseNotesFile>$(RepoRoot)RELEASENOTES.md</PackageReleaseNotesFile> -->
</PropertyGroup>

<ItemGroup>
<!-- <None Include="$(RepoRoot)icon-512.png" Pack="true" PackagePath="\" /> -->
</ItemGroup>

<!-- Enable sourcelink https://docs.microsoft.com/dotnet/standard/library-guidance/sourcelink -->
<PropertyGroup Label="SourceLinkProperties">
<PublishRepositoryUrl>true</PublishRepositoryUrl>
Expand All @@ -42,7 +45,7 @@

<PropertyGroup>
<SignAssembly>true</SignAssembly>
<AssemblyOriginatorKeyFile>$(RepoRoot)sign.snk</AssemblyOriginatorKeyFile>
<AssemblyOriginatorKeyFile>$(RepoRoot)/sign.snk</AssemblyOriginatorKeyFile>
</PropertyGroup>

<PropertyGroup Condition="'$(Configuration)'=='Debug'">
Expand Down
7 changes: 7 additions & 0 deletions Directory.Build.targets
Original file line number Diff line number Diff line change
@@ -1,5 +1,12 @@
<Project>

<ItemGroup Label="Analyzers">
<PackageReference Include="Microsoft.VisualStudio.Threading.Analyzers">
<PrivateAssets>all</PrivateAssets>
<IncludeAssets>runtime; build; native; contentfiles; analyzers; buildtransitive</IncludeAssets>
</PackageReference>
</ItemGroup>

<ItemGroup Label="Fody">
<PackageReference Include="ConfigureAwait.Fody">
<PrivateAssets>all</PrivateAssets>
Expand Down
28 changes: 20 additions & 8 deletions Directory.Packages.props
Original file line number Diff line number Diff line change
@@ -1,16 +1,28 @@
<Project>

<PropertyGroup>
<ManagePackageVersionsCentrally>true</ManagePackageVersionsCentrally>
</PropertyGroup>

<ItemGroup Label="Microsoft">
<PackageVersion Include="Microsoft.Extensions.DependencyInjection" Version="8.0.1" />
<PackageVersion Include="Microsoft.Extensions.DependencyInjection.Abstractions" Version="8.0.2" />
</ItemGroup>
<ItemGroup Label="Test">
<PackageVersion Include="BenchmarkDotNet" Version="0.14.0" />
<PackageVersion Include="FluentAssertions" Version="6.12.2" />
<PackageVersion Include="Testcontainers" Version="4.0.0" />
<PackageVersion Include="coverlet.collector" Version="6.0.2" />
<PackageVersion Include="Microsoft.NET.Test.Sdk" Version="17.11.1" />
<PackageVersion Include="xunit" Version="2.9.2" />
<PackageVersion Include="xunit.runner.visualstudio" Version="2.8.2" />
</ItemGroup>
<ItemGroup Label="Fody">
<PackageVersion Include="ConfigureAwait.Fody" Version="[3.3.2,]" />
<PackageVersion Include="Fody" Version="[6.8.1,]" />
<PackageVersion Include="ConfigureAwait.Fody" Version="3.3.2" />
<PackageVersion Include="Fody" Version="6.8.2" />
</ItemGroup>
<ItemGroup Label="Analyzer">
<PackageVersion Include="Microsoft.VisualStudio.Threading.Analyzers" Version="17.11.20" />
</ItemGroup>

<ItemGroup Label="SourceLinkProperties">
<PackageVersion Include="Microsoft.SourceLink.GitHub" Version="1.1.1" />
<PackageVersion Include="Microsoft.SourceLink.GitHub" Version="8.0.0" />
</ItemGroup>

</Project>
</Project>
15 changes: 0 additions & 15 deletions Repository.slnx

This file was deleted.

Binary file added icon-512.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file modified icon.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
<Project Sdk="Microsoft.NET.Sdk">

<PropertyGroup>
<Version>0.1.0-alpha</Version>
</PropertyGroup>

</Project>
Original file line number Diff line number Diff line change
@@ -0,0 +1,14 @@
// Copyright AdHoc Authors
// SPDX-License-Identifier: MIT

namespace AdHoc.Locking.Abstraction;
public interface IDistributedAtomicLock
: IAtomicLock,
IDistributedLock<IDistributedAtomicLocking>
{
ILocking ILock.Create() =>
((ILock<IDistributedAtomicLocking>)this).Create();

IAtomicLocking ILock<IAtomicLocking>.Create() =>
((ILock<IDistributedAtomicLocking>)this).Create();
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
// Copyright AdHoc Authors
// SPDX-License-Identifier: MIT

namespace AdHoc.Locking.Abstraction;
public interface IDistributedAtomicLockProvider
: IAtomicLockProvider,
IDistributedLockProvider<IDistributedAtomicLock>
{
ILock ILockProvider.GetLock(string name) =>
((ILockProvider<IDistributedAtomicLock>)this).GetLock(name);
IAtomicLock ILockProvider<IAtomicLock>.GetLock(string name) =>
((ILockProvider<IDistributedAtomicLock>)this).GetLock(name);
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
// Copyright AdHoc Authors
// SPDX-License-Identifier: MIT

namespace AdHoc.Locking.Abstraction;

public interface IDistributedAtomicLocking
: IAtomicLocking,
IDistributedLocking
{
ValueTask<bool> IsAcquiredAsync(CancellationToken cancellationToken);
}
3 changes: 3 additions & 0 deletions src/AdHoc.Locking.Abstraction/Atomic/IAtomicLock.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
namespace AdHoc.Locking.Abstraction;
public interface IAtomicLock
: ILock<IAtomicLocking>;
3 changes: 3 additions & 0 deletions src/AdHoc.Locking.Abstraction/Atomic/IAtomicLockProvider.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
namespace AdHoc.Locking.Abstraction;
public interface IAtomicLockProvider
: ILockProvider<IAtomicLock>;
6 changes: 6 additions & 0 deletions src/AdHoc.Locking.Abstraction/Atomic/IAtomicLocking.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
namespace AdHoc.Locking.Abstraction;
public interface IAtomicLocking
: ILocking
{
bool IsAcquired { get; }
}
24 changes: 24 additions & 0 deletions src/AdHoc.Locking.Abstraction/Distributed/IDistributedLock.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,24 @@
// Copyright AdHoc Authors
// SPDX-License-Identifier: MIT

using System.ComponentModel;

namespace AdHoc.Locking.Abstraction;
public interface IDistributedLock
: ILock
{
IDistributedLocking Create(string owner);
}


[EditorBrowsable(EditorBrowsableState.Advanced)]
public interface IDistributedLock<TLocking>
: IDistributedLock,
ILock<TLocking>
where TLocking : IDistributedLocking
{
new TLocking Create(string owner);

IDistributedLocking IDistributedLock.Create(string owner) =>
Create(owner);
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,30 @@
// Copyright AdHoc Authors
// SPDX-License-Identifier: MIT

using System.ComponentModel;

namespace AdHoc.Locking.Abstraction;
public interface IDistributedLockProvider
: ILockProvider
{
new IDistributedLock GetLock(string name);

ILock ILockProvider.GetLock(string name) =>
GetLock(name);


void SetExpiryInterval(string? name, TimeSpan expiryInterval);
}


[EditorBrowsable(EditorBrowsableState.Advanced)]
public interface IDistributedLockProvider<TLock>
: IDistributedLockProvider,
ILockProvider<TLock>
where TLock : IDistributedLock
{
IDistributedLock IDistributedLockProvider.GetLock(string name) =>
((ILockProvider<TLock>)this).GetLock(name);
ILock ILockProvider.GetLock(string name) =>
((ILockProvider<TLock>)this).GetLock(name);
}
Loading

0 comments on commit dcefc74

Please sign in to comment.