Skip to content

Commit

Permalink
Remove XThread as obsolete
Browse files Browse the repository at this point in the history
  • Loading branch information
nayato committed Jul 19, 2021
1 parent 1cdaadb commit 05e5aa4
Show file tree
Hide file tree
Showing 15 changed files with 14 additions and 131 deletions.
2 changes: 1 addition & 1 deletion src/DotNetty.Buffers/PoolThreadCache.cs
Original file line number Diff line number Diff line change
Expand Up @@ -6,10 +6,10 @@ namespace DotNetty.Buffers
using System;
using System.Diagnostics;
using System.Diagnostics.Contracts;
using System.Threading;
using DotNetty.Common;
using DotNetty.Common.Internal;
using DotNetty.Common.Internal.Logging;
using Thread = DotNetty.Common.Concurrency.XThread;

/// <summary>
/// Acts a Thread cache for allocations. This implementation is moduled after
Expand Down
1 change: 0 additions & 1 deletion src/DotNetty.Common/Concurrency/AbstractEventExecutor.cs
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,6 @@ namespace DotNetty.Common.Concurrency
using System.Threading;
using System.Threading.Tasks;
using DotNetty.Common.Internal.Logging;
using Thread = XThread;

/// <summary>
/// Abstract base class for <see cref="IEventExecutor" /> implementations
Expand Down
4 changes: 2 additions & 2 deletions src/DotNetty.Common/Concurrency/IEventExecutor.cs
Original file line number Diff line number Diff line change
Expand Up @@ -3,8 +3,8 @@

namespace DotNetty.Common.Concurrency
{
using Thread = DotNetty.Common.Concurrency.XThread;

using System.Threading;
public interface IEventExecutor : IEventExecutorGroup
{
/// <summary>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,6 @@ namespace DotNetty.Common.Concurrency
using System.Threading.Tasks;
using DotNetty.Common.Internal;
using DotNetty.Common.Internal.Logging;
using Thread = XThread;

/// <summary>
/// <see cref="IEventExecutor"/> backed by a single thread.
Expand Down
107 changes: 0 additions & 107 deletions src/DotNetty.Common/Concurrency/XThread.cs

This file was deleted.

1 change: 0 additions & 1 deletion src/DotNetty.Common/ThreadDeathWatcher.cs
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,6 @@ namespace DotNetty.Common
using DotNetty.Common.Concurrency;
using DotNetty.Common.Internal;
using DotNetty.Common.Internal.Logging;
using Thread = DotNetty.Common.Concurrency.XThread;

public static class ThreadDeathWatcher
{
Expand Down
1 change: 0 additions & 1 deletion src/DotNetty.Common/ThreadLocalPool.cs
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,6 @@ namespace DotNetty.Common
using System.Diagnostics.Contracts;
using System.Runtime.CompilerServices;
using System.Threading;
using Thread = DotNetty.Common.Concurrency.XThread;

public class ThreadLocalPool
{
Expand Down
6 changes: 3 additions & 3 deletions src/DotNetty.Common/Utilities/HashedWheelTimer.cs
Original file line number Diff line number Diff line change
Expand Up @@ -27,7 +27,7 @@ public sealed class HashedWheelTimer : ITimer
const int InstanceCountLimit = 64;

readonly Worker worker;
readonly XThread workerThread;
readonly Thread workerThread;
readonly CancellationTokenSource cancellationTokenSource = new CancellationTokenSource();

const int WorkerStateInit = 0;
Expand Down Expand Up @@ -98,7 +98,7 @@ public HashedWheelTimer(
tickInterval,
long.MaxValue / this.wheel.Length));
}
this.workerThread = new XThread(st => this.worker.Run());
this.workerThread = new Thread(st => this.worker.Run());

this.maxPendingTimeouts = maxPendingTimeouts;

Expand Down Expand Up @@ -187,7 +187,7 @@ public async Task<ISet<ITimeout>> StopAsync()
{
GC.SuppressFinalize(this);

if (XThread.CurrentThread == this.workerThread)
if (Thread.CurrentThread == this.workerThread)
{
throw new InvalidOperationException($"{nameof(HashedWheelTimer)}.stop() cannot be called from timer task.");
}
Expand Down
1 change: 0 additions & 1 deletion src/DotNetty.Common/Utilities/ReferenceCountUtil.cs
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,6 @@ namespace DotNetty.Common.Utilities
using System;
using System.Threading;
using DotNetty.Common.Internal.Logging;
using Thread = DotNetty.Common.Concurrency.XThread;

public static class ReferenceCountUtil
{
Expand Down
1 change: 0 additions & 1 deletion src/DotNetty.Common/Utilities/ThreadExtensions.cs
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,6 @@ namespace DotNetty.Common.Utilities
using System;
using System.Diagnostics.Contracts;
using System.Threading;
using Thread = DotNetty.Common.Concurrency.XThread;

public static class ThreadExtensions
{
Expand Down
2 changes: 1 addition & 1 deletion src/DotNetty.Transport.Libuv/EventLoopGroup.cs
Original file line number Diff line number Diff line change
Expand Up @@ -74,7 +74,7 @@ public EventLoopGroup(int eventLoopCount)
public override IEventExecutor GetNext()
{
// Attempt to select event loop based on thread first
int threadId = XThread.CurrentThread.Id;
int threadId = Thread.CurrentThread.ManagedThreadId;
int i;
for (i = 0; i < this.eventLoops.Length; i++)
{
Expand Down
8 changes: 4 additions & 4 deletions src/DotNetty.Transport.Libuv/LoopExecutor.cs
Original file line number Diff line number Diff line change
Expand Up @@ -36,7 +36,7 @@ class LoopExecutor : AbstractScheduledEventExecutor
readonly ThreadLocalPool<WriteRequest> writeRequestPool = new ThreadLocalPool<WriteRequest>(handle => new WriteRequest(handle));
readonly long preciseBreakoutInterval;
readonly IQueue<IRunnable> taskQueue;
readonly XThread thread;
readonly Thread thread;
readonly TaskScheduler scheduler;
readonly ManualResetEventSlim loopRunStart;
readonly TaskCompletionSource terminationCompletionSource;
Expand Down Expand Up @@ -80,7 +80,7 @@ public LoopExecutor(IEventLoopGroup parent, string threadName, TimeSpan breakout
{
name = $"{name}({threadName})";
}
this.thread = new XThread(Run) { Name = name };
this.thread = new Thread(Run) { Name = name };
this.loopRunStart = new ManualResetEventSlim(false, 1);
}

Expand All @@ -97,7 +97,7 @@ protected void Start()

internal Loop UnsafeLoop => this.loop;

internal int LoopThreadId => this.thread.Id;
internal int LoopThreadId => this.thread.ManagedThreadId;

static void Run(object state)
{
Expand Down Expand Up @@ -424,7 +424,7 @@ static IRunnable PollTaskFrom(IQueue<IRunnable> taskQueue) =>

public override bool IsTerminated => this.executionState == TerminatedState;

public override bool IsInEventLoop(XThread t) => this.thread == t;
public override bool IsInEventLoop(Thread t) => this.thread == t;

void WakeUp(bool inEventLoop)
{
Expand Down
1 change: 0 additions & 1 deletion src/DotNetty.Transport/Channels/DefaultChannelPipeline.cs
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,6 @@ namespace DotNetty.Transport.Channels
using DotNetty.Common.Concurrency;
using DotNetty.Common.Internal.Logging;
using DotNetty.Common.Utilities;
using Thread = DotNetty.Common.Concurrency.XThread;

public class DefaultChannelPipeline : IChannelPipeline
{
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -5,10 +5,10 @@ namespace DotNetty.Transport.Channels.Embedded
{
using System;
using System.Collections.Generic;
using System.Threading;
using System.Threading.Tasks;
using DotNetty.Common;
using DotNetty.Common.Concurrency;
using Thread = DotNetty.Common.Concurrency.XThread;

sealed class EmbeddedEventLoop : AbstractScheduledEventExecutor, IEventLoop
{
Expand Down
7 changes: 2 additions & 5 deletions test/DotNetty.Common.Tests/ThreadLocalPoolTest.cs
Original file line number Diff line number Diff line change
Expand Up @@ -23,14 +23,13 @@ public void ThreadCanBeCollectedEvenIfHandledObjectIsReferencedTest()
ThreadLocalPool<HandledObject> pool = NewPool(1024);
HandledObject reference = null;
WeakReference<Thread> threadRef = null;
WeakReference<XThread> xThreadRef = null;

var thread1 = new Thread(() =>
{
//Don't know the reason, but thread2 will not be collected without wrapped with thread1
var thread2 = new Thread(() =>
{
Volatile.Write(ref xThreadRef, new WeakReference<XThread>(XThread.CurrentThread));
Volatile.Write(ref threadRef, new WeakReference<Thread>(Thread.CurrentThread));
HandledObject data = pool.Take();
// Store a reference to the HandledObject to ensure it is not collected when the run method finish.
Volatile.Write(ref reference, data);
Expand All @@ -39,7 +38,6 @@ public void ThreadCanBeCollectedEvenIfHandledObjectIsReferencedTest()
thread2.Start();
thread2.Join();
Assert.True(Volatile.Read(ref threadRef)?.TryGetTarget(out _));
Assert.True(Volatile.Read(ref xThreadRef)?.TryGetTarget(out _));
GC.KeepAlive(thread2);
// Null out so it can be collected.
Expand All @@ -53,12 +51,11 @@ public void ThreadCanBeCollectedEvenIfHandledObjectIsReferencedTest()
GC.Collect(GC.MaxGeneration, GCCollectionMode.Forced, true);
GC.WaitForPendingFinalizers();

if (Volatile.Read(ref threadRef)?.TryGetTarget(out _) == true || Volatile.Read(ref xThreadRef)?.TryGetTarget(out _) == true)
if (Volatile.Read(ref threadRef)?.TryGetTarget(out _) == true || Volatile.Read(ref threadRef)?.TryGetTarget(out _) == true)
Thread.Sleep(100);
}

Assert.False(Volatile.Read(ref threadRef)?.TryGetTarget(out _));
Assert.False(Volatile.Read(ref xThreadRef)?.TryGetTarget(out _));

// Now call recycle after the Thread was collected to ensure this still works...
reference.Release();
Expand Down

1 comment on commit 05e5aa4

@roc916
Copy link

@roc916 roc916 commented on 05e5aa4 Jul 28, 2021

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

System.Threading.ThreadAbortException: Thread was being aborted

Please sign in to comment.