Skip to content

Commit 57af627

Browse files
committed
Initial commit
0 parents  commit 57af627

File tree

12 files changed

+410
-0
lines changed

12 files changed

+410
-0
lines changed

.gitignore

Lines changed: 40 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,40 @@
1+
# Autosave files
2+
*~
3+
4+
# build
5+
[Oo]bj/
6+
[Bb]in/
7+
packages/
8+
TestResults/
9+
10+
# globs
11+
Makefile.in
12+
*.DS_Store
13+
*.sln.cache
14+
*.suo
15+
*.cache
16+
*.pidb
17+
*.userprefs
18+
*.usertasks
19+
config.log
20+
config.make
21+
config.status
22+
aclocal.m4
23+
install-sh
24+
autom4te.cache/
25+
*.user
26+
*.tar.gz
27+
tarballs/
28+
test-results/
29+
Thumbs.db
30+
31+
# Mac bundle stuff
32+
*.dmg
33+
*.app
34+
35+
# resharper
36+
*_Resharper.*
37+
*.Resharper
38+
39+
# dotCover
40+
*.dotCover

Wait.NuGet/Wait.NuGet.nuget.props

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,9 @@
1+
<?xml version="1.0" encoding="utf-8" standalone="no"?>
2+
<Project ToolsVersion="14.0" xmlns="http://schemas.microsoft.com/developer/msbuild/2003">
3+
<PropertyGroup Condition="'$(NuGetPackageRoot)' == ''">
4+
<NuGetPackageRoot>/Users/ben/.nuget/packages/</NuGetPackageRoot>
5+
</PropertyGroup>
6+
<ImportGroup>
7+
<Import Project="$(NuGetPackageRoot)nuget.build.packaging/0.2.1/build/NuGet.Build.Packaging.props" Condition="Exists('$(NuGetPackageRoot)nuget.build.packaging/0.2.1/build/NuGet.Build.Packaging.props')" />
8+
</ImportGroup>
9+
</Project>
Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,9 @@
1+
<?xml version="1.0" encoding="utf-8" standalone="no"?>
2+
<Project ToolsVersion="14.0" xmlns="http://schemas.microsoft.com/developer/msbuild/2003">
3+
<PropertyGroup Condition="'$(NuGetPackageRoot)' == ''">
4+
<NuGetPackageRoot>/Users/ben/.nuget/packages/</NuGetPackageRoot>
5+
</PropertyGroup>
6+
<ImportGroup>
7+
<Import Project="$(NuGetPackageRoot)nuget.build.packaging/0.2.1/build/NuGet.Build.Packaging.targets" Condition="Exists('$(NuGetPackageRoot)nuget.build.packaging/0.2.1/build/NuGet.Build.Packaging.targets')" />
8+
</ImportGroup>
9+
</Project>

Wait.NuGet/Wait.NuGet.nuproj

Lines changed: 43 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,43 @@
1+
<?xml version="1.0" encoding="utf-8"?>
2+
<Project DefaultTargets="Build" ToolsVersion="4.0" xmlns="http://schemas.microsoft.com/developer/msbuild/2003">
3+
<Import Project="$(NuGetAuthoringPath)\NuGet.Packaging.Authoring.props" Condition="Exists('$(NuGetAuthoringPath)\NuGet.Packaging.Authoring.props')" />
4+
<PropertyGroup>
5+
<Configuration Condition=" '$(Configuration)' == '' ">Debug</Configuration>
6+
<Platform Condition=" '$(Platform)' == '' ">AnyCPU</Platform>
7+
<ProjectGuid>{25D1FFC4-47A0-4237-91C0-6ED25A91E4C3}</ProjectGuid>
8+
<Description>An obsessively simple and performant library for protecting critical sections.</Description>
9+
<PackageId>wait</PackageId>
10+
<PackageVersion>1.0.0</PackageVersion>
11+
<Authors>Ben Barth</Authors>
12+
<DevelopmentDependency>false</DevelopmentDependency>
13+
<PackageRequireLicenseAcceptance>false</PackageRequireLicenseAcceptance>
14+
<OutputType>Exe</OutputType>
15+
<RootNamespace>Wait.NuGet</RootNamespace>
16+
<UsePartialTypes>false</UsePartialTypes>
17+
<AssemblyName>Wait.NuGet</AssemblyName>
18+
<TargetFrameworkVersion>v4.5</TargetFrameworkVersion>
19+
</PropertyGroup>
20+
<PropertyGroup Condition=" '$(Configuration)|$(Platform)' == 'Debug|AnyCPU' ">
21+
<DebugSymbols>true</DebugSymbols>
22+
<DebugType>full</DebugType>
23+
<OutputPath>bin\Debug</OutputPath>
24+
<ErrorReport>prompt</ErrorReport>
25+
</PropertyGroup>
26+
<PropertyGroup Condition=" '$(Configuration)|$(Platform)' == 'Release|AnyCPU' ">
27+
<OutputPath>bin\Release</OutputPath>
28+
<ErrorReport>prompt</ErrorReport>
29+
</PropertyGroup>
30+
<ItemGroup>
31+
<None Include="readme.txt">
32+
<IncludeInPackage>true</IncludeInPackage>
33+
</None>
34+
</ItemGroup>
35+
<ItemGroup>
36+
<PackageReference Include="NuGet.Build.Packaging">
37+
<Version>0.2.1</Version>
38+
<PrivateAssets>All</PrivateAssets>
39+
</PackageReference>
40+
</ItemGroup>
41+
<Import Project="$(MSBuildBinPath)\Microsoft.Common.targets" />
42+
<Import Project="$(NuGetAuthoringPath)\NuGet.Packaging.Authoring.targets" Condition="Exists('$(NuGetAuthoringPath)\NuGet.Packaging.Authoring.targets')" />
43+
</Project>

Wait.NuGet/readme.txt

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,2 @@
1+

2+
Wait - An obsessively simple and performant library for protecting critical sections.

Wait.Tests/Wait.Tests.csproj

Lines changed: 47 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,47 @@
1+
<?xml version="1.0" encoding="utf-8"?>
2+
<Project DefaultTargets="Build" ToolsVersion="4.0" xmlns="http://schemas.microsoft.com/developer/msbuild/2003">
3+
<PropertyGroup>
4+
<Configuration Condition=" '$(Configuration)' == '' ">Debug</Configuration>
5+
<Platform Condition=" '$(Platform)' == '' ">AnyCPU</Platform>
6+
<ProjectGuid>{103FF9E5-BF80-492D-B85C-65F3F793C855}</ProjectGuid>
7+
<OutputType>Library</OutputType>
8+
<RootNamespace>Wait.Tests</RootNamespace>
9+
<AssemblyName>Wait.Tests</AssemblyName>
10+
<TargetFrameworkVersion>v4.6.1</TargetFrameworkVersion>
11+
</PropertyGroup>
12+
<PropertyGroup Condition=" '$(Configuration)|$(Platform)' == 'Debug|AnyCPU' ">
13+
<DebugSymbols>true</DebugSymbols>
14+
<DebugType>full</DebugType>
15+
<Optimize>false</Optimize>
16+
<OutputPath>bin\Debug</OutputPath>
17+
<DefineConstants>DEBUG;</DefineConstants>
18+
<ErrorReport>prompt</ErrorReport>
19+
<WarningLevel>4</WarningLevel>
20+
</PropertyGroup>
21+
<PropertyGroup Condition=" '$(Configuration)|$(Platform)' == 'Release|AnyCPU' ">
22+
<Optimize>true</Optimize>
23+
<OutputPath>bin\Release</OutputPath>
24+
<ErrorReport>prompt</ErrorReport>
25+
<WarningLevel>4</WarningLevel>
26+
</PropertyGroup>
27+
<ItemGroup>
28+
<Reference Include="System" />
29+
<Reference Include="nunit.framework">
30+
<HintPath>..\packages\NUnit.3.8.1\lib\net45\nunit.framework.dll</HintPath>
31+
</Reference>
32+
</ItemGroup>
33+
<ItemGroup>
34+
<Compile Include="WaiterTests.cs" />
35+
<Compile Include="WaitTests.cs" />
36+
</ItemGroup>
37+
<ItemGroup>
38+
<None Include="packages.config" />
39+
</ItemGroup>
40+
<ItemGroup>
41+
<ProjectReference Include="..\Wait\Wait.csproj">
42+
<Project>{135D41F8-56CE-4E92-965D-F0ACC3CBC44D}</Project>
43+
<Name>Wait</Name>
44+
</ProjectReference>
45+
</ItemGroup>
46+
<Import Project="$(MSBuildBinPath)\Microsoft.CSharp.targets" />
47+
</Project>

Wait.Tests/WaitTests.cs

Lines changed: 63 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,63 @@
1+
using System;
2+
using System.Threading;
3+
using System.Threading.Tasks;
4+
using Waiting;
5+
using NUnit.Framework;
6+
7+
namespace WaitTests
8+
{
9+
[TestFixture()]
10+
public class WaitTests
11+
{
12+
[Test()]
13+
public void ExampleUsage()
14+
{
15+
Wait.On("critical section", () =>
16+
{
17+
// Only one "critical section" will run at a time
18+
});
19+
20+
// Imagine this running on a different thread
21+
Wait.On("critical section", () =>
22+
{
23+
// This might take a while
24+
});
25+
26+
Assert.Pass();
27+
}
28+
29+
[Test()]
30+
public void TestWaitWithAction()
31+
{
32+
var waited = 0;
33+
34+
// Long running task
35+
new Thread(() =>
36+
{
37+
Wait.On("test", () =>
38+
{
39+
Thread.Sleep(300);
40+
Assert.AreEqual(0, waited);
41+
waited++;
42+
});
43+
}).Start();
44+
45+
// Long running task
46+
new Thread(() =>
47+
{
48+
Wait.On("test", () =>
49+
{
50+
Thread.Sleep(200);
51+
Assert.AreEqual(1, waited);
52+
waited++;
53+
});
54+
}).Start();
55+
56+
Thread.Sleep(100);
57+
Wait.On("test", () =>
58+
{
59+
Assert.AreEqual(2, waited);
60+
});
61+
}
62+
}
63+
}

Wait.Tests/WaiterTests.cs

Lines changed: 71 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,71 @@
1+
using System;
2+
using System.Threading;
3+
using Waiting;
4+
using NUnit.Framework;
5+
6+
namespace WaitTests
7+
{
8+
[TestFixture()]
9+
public class WaiterTests
10+
{
11+
[Test()]
12+
public void ExampleUsage()
13+
{
14+
Waiter waiter = Wait.GetWaiter();
15+
16+
new Thread(() =>
17+
{
18+
// Downloading
19+
waiter.Done();
20+
}).Start();
21+
22+
waiter.WaitUntilDone();
23+
// Download is done
24+
25+
Assert.Pass();
26+
}
27+
28+
[Test()]
29+
public void TestWaitWithWaiter()
30+
{
31+
var waited = false;
32+
var waiter = Wait.GetWaiter();
33+
34+
// Long running task
35+
new Thread(() =>
36+
{
37+
Thread.Sleep(100);
38+
waited = true;
39+
waiter.Done();
40+
}).Start();
41+
42+
Assert.False(waited);
43+
waiter.WaitUntilDone();
44+
Assert.True(waited);
45+
}
46+
47+
[Test()]
48+
public void TestWaiterWithMultipleDones()
49+
{
50+
var waited = false;
51+
var waiter = Wait.GetWaiter();
52+
53+
// Long running task
54+
new Thread(() =>
55+
{
56+
Assert.Throws<System.Threading.SemaphoreFullException>(() =>
57+
{
58+
Thread.Sleep(100);
59+
waited = true;
60+
waiter.Done();
61+
waiter.Done();
62+
});
63+
}).Start();
64+
65+
Assert.False(waited);
66+
waiter.WaitUntilDone();
67+
Assert.True(waited);
68+
}
69+
70+
}
71+
}

Wait.Tests/packages.config

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,4 @@
1+
<?xml version="1.0" encoding="utf-8"?>
2+
<packages>
3+
<package id="NUnit" version="3.8.1" targetFramework="net461" />
4+
</packages>

Wait.sln

Lines changed: 29 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,29 @@
1+
2+
Microsoft Visual Studio Solution File, Format Version 12.00
3+
# Visual Studio 2012
4+
Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "Wait", "Wait\Wait.csproj", "{135D41F8-56CE-4E92-965D-F0ACC3CBC44D}"
5+
EndProject
6+
Project("{5DD5E4FA-CB73-4610-85AB-557B54E96AA9}") = "Wait.NuGet", "Wait.NuGet\Wait.NuGet.nuproj", "{25D1FFC4-47A0-4237-91C0-6ED25A91E4C3}"
7+
EndProject
8+
Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "Wait.Tests", "Wait.Tests\Wait.Tests.csproj", "{103FF9E5-BF80-492D-B85C-65F3F793C855}"
9+
EndProject
10+
Global
11+
GlobalSection(SolutionConfigurationPlatforms) = preSolution
12+
Debug|Any CPU = Debug|Any CPU
13+
Release|Any CPU = Release|Any CPU
14+
EndGlobalSection
15+
GlobalSection(ProjectConfigurationPlatforms) = postSolution
16+
{135D41F8-56CE-4E92-965D-F0ACC3CBC44D}.Debug|Any CPU.ActiveCfg = Debug|Any CPU
17+
{135D41F8-56CE-4E92-965D-F0ACC3CBC44D}.Debug|Any CPU.Build.0 = Debug|Any CPU
18+
{135D41F8-56CE-4E92-965D-F0ACC3CBC44D}.Release|Any CPU.ActiveCfg = Release|Any CPU
19+
{135D41F8-56CE-4E92-965D-F0ACC3CBC44D}.Release|Any CPU.Build.0 = Release|Any CPU
20+
{25D1FFC4-47A0-4237-91C0-6ED25A91E4C3}.Debug|Any CPU.ActiveCfg = Debug|Any CPU
21+
{25D1FFC4-47A0-4237-91C0-6ED25A91E4C3}.Debug|Any CPU.Build.0 = Debug|Any CPU
22+
{25D1FFC4-47A0-4237-91C0-6ED25A91E4C3}.Release|Any CPU.ActiveCfg = Release|Any CPU
23+
{25D1FFC4-47A0-4237-91C0-6ED25A91E4C3}.Release|Any CPU.Build.0 = Release|Any CPU
24+
{103FF9E5-BF80-492D-B85C-65F3F793C855}.Debug|Any CPU.ActiveCfg = Debug|Any CPU
25+
{103FF9E5-BF80-492D-B85C-65F3F793C855}.Debug|Any CPU.Build.0 = Debug|Any CPU
26+
{103FF9E5-BF80-492D-B85C-65F3F793C855}.Release|Any CPU.ActiveCfg = Release|Any CPU
27+
{103FF9E5-BF80-492D-B85C-65F3F793C855}.Release|Any CPU.Build.0 = Release|Any CPU
28+
EndGlobalSection
29+
EndGlobal

0 commit comments

Comments
 (0)