Skip to content

Commit

Permalink
Fix concurrent list
Browse files Browse the repository at this point in the history
  • Loading branch information
jtheisen committed Jan 25, 2023
1 parent 195a17c commit ef0dd78
Show file tree
Hide file tree
Showing 2 changed files with 4 additions and 9 deletions.
11 changes: 3 additions & 8 deletions Moldinium/Misc/ConcurrentList.cs
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@

namespace Moldinium.Misc;

struct LockHelper : IDisposable
class LockHelper : IDisposable
{
SpinLock spinLock;

Expand Down Expand Up @@ -36,11 +36,6 @@ public void Dispose()
}
}

ref struct LockHelperRef
{
public ref int lockHelper;
}

/// <summary>
/// A simple but likely quite inefficient implementation of a concurrent list that
/// is meant only for demonstration purposes.
Expand All @@ -49,7 +44,7 @@ public class ConcurrentList<T> : IList<T>
{
IImmutableList<T> list = ImmutableList<T>.Empty;

LockHelper locker;
LockHelper locker = new LockHelper();

public T this[int index]
{
Expand All @@ -70,7 +65,7 @@ public void Add(T item)
{
using var _ = locker.Lock();

list.Add(item);
list = list.Add(item);
}

public void Clear()
Expand Down
2 changes: 1 addition & 1 deletion SampleApp.AspNetMvc/SampleApp.AspNetMvc.csproj
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
<Project Sdk="Microsoft.NET.Sdk.Web">

<PropertyGroup>
<TargetFramework>net6.0</TargetFramework>
<TargetFramework>net7.0</TargetFramework>
<Nullable>enable</Nullable>
<ImplicitUsings>enable</ImplicitUsings>
</PropertyGroup>
Expand Down

0 comments on commit ef0dd78

Please sign in to comment.