Skip to content

Commit

Permalink
Make Thread a readonly struct
Browse files Browse the repository at this point in the history
  • Loading branch information
elinor-fung committed May 10, 2024
1 parent fa4f669 commit 1ad1da3
Show file tree
Hide file tree
Showing 3 changed files with 13 additions and 11 deletions.
2 changes: 1 addition & 1 deletion src/native/managed/cdacreader/src/Contracts/Registry.cs
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,7 @@ public Registry(Target target)
_target = target;
}

public Thread Thread => GetContract<Thread>();
public IThread Thread => GetContract<IThread>();

private T GetContract<T>() where T : IContract
{
Expand Down
20 changes: 11 additions & 9 deletions src/native/managed/cdacreader/src/Contracts/Thread.cs
Original file line number Diff line number Diff line change
Expand Up @@ -10,26 +10,28 @@ public record struct ThreadStoreData(
int ThreadCount,
TargetPointer FirstThread);

internal class Thread : IContract
internal interface IThread : IContract
{
public static Thread NotImplemented = new Thread();

public static string Name { get; } = nameof(Thread);

public static IContract Create(Target target, int version)
static string IContract.Name { get; } = nameof(Thread);
static IContract IContract.Create(Target target, int version)
{
TargetPointer threadStore = target.ReadGlobalPointer(Constants.Globals.ThreadStore);
return version switch
{
1 => new Thread_1(target, threadStore),
_ => NotImplemented,
_ => default(Thread),
};
}

public virtual ThreadStoreData GetThreadStoreData() => throw new NotImplementedException();
}

internal sealed class Thread_1 : Thread
internal readonly struct Thread : IThread
{
// Everything throws NotImplementedException
}

internal readonly struct Thread_1 : IThread
{
private readonly Target _target;
private readonly TargetPointer _threadStoreAddr;
Expand All @@ -40,7 +42,7 @@ internal Thread_1(Target target, TargetPointer threadStore)
_threadStoreAddr = threadStore;
}

public override ThreadStoreData GetThreadStoreData()
ThreadStoreData IThread.GetThreadStoreData()
{
Data.ThreadStore? threadStore;
if (!_target.ProcessedData.TryGet(_threadStoreAddr.Value, out threadStore))
Expand Down
2 changes: 1 addition & 1 deletion src/native/managed/cdacreader/src/Legacy/SOSDacImpl.cs
Original file line number Diff line number Diff line change
Expand Up @@ -111,7 +111,7 @@ public unsafe int GetThreadStoreData(DacpThreadStoreData* data)
{
try
{
Contracts.Thread thread = _target.Contracts.Thread;
Contracts.IThread thread = _target.Contracts.Thread;
Contracts.ThreadStoreData threadStoreData = thread.GetThreadStoreData();
data->threadCount = threadStoreData.ThreadCount;
data->firstThread = threadStoreData.FirstThread.Value;
Expand Down

0 comments on commit 1ad1da3

Please sign in to comment.