Skip to content

Commit 05e5aa4

Browse files
committed
Remove XThread as obsolete
1 parent 1cdaadb commit 05e5aa4

File tree

15 files changed

+14
-131
lines changed

15 files changed

+14
-131
lines changed

src/DotNetty.Buffers/PoolThreadCache.cs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -6,10 +6,10 @@ namespace DotNetty.Buffers
66
using System;
77
using System.Diagnostics;
88
using System.Diagnostics.Contracts;
9+
using System.Threading;
910
using DotNetty.Common;
1011
using DotNetty.Common.Internal;
1112
using DotNetty.Common.Internal.Logging;
12-
using Thread = DotNetty.Common.Concurrency.XThread;
1313

1414
/// <summary>
1515
/// Acts a Thread cache for allocations. This implementation is moduled after

src/DotNetty.Common/Concurrency/AbstractEventExecutor.cs

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,6 @@ namespace DotNetty.Common.Concurrency
88
using System.Threading;
99
using System.Threading.Tasks;
1010
using DotNetty.Common.Internal.Logging;
11-
using Thread = XThread;
1211

1312
/// <summary>
1413
/// Abstract base class for <see cref="IEventExecutor" /> implementations

src/DotNetty.Common/Concurrency/IEventExecutor.cs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -3,8 +3,8 @@
33

44
namespace DotNetty.Common.Concurrency
55
{
6-
using Thread = DotNetty.Common.Concurrency.XThread;
7-
6+
using System.Threading;
7+
88
public interface IEventExecutor : IEventExecutorGroup
99
{
1010
/// <summary>

src/DotNetty.Common/Concurrency/SingleThreadEventExecutor.cs

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -12,7 +12,6 @@ namespace DotNetty.Common.Concurrency
1212
using System.Threading.Tasks;
1313
using DotNetty.Common.Internal;
1414
using DotNetty.Common.Internal.Logging;
15-
using Thread = XThread;
1615

1716
/// <summary>
1817
/// <see cref="IEventExecutor"/> backed by a single thread.

src/DotNetty.Common/Concurrency/XThread.cs

Lines changed: 0 additions & 107 deletions
This file was deleted.

src/DotNetty.Common/ThreadDeathWatcher.cs

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -10,7 +10,6 @@ namespace DotNetty.Common
1010
using DotNetty.Common.Concurrency;
1111
using DotNetty.Common.Internal;
1212
using DotNetty.Common.Internal.Logging;
13-
using Thread = DotNetty.Common.Concurrency.XThread;
1413

1514
public static class ThreadDeathWatcher
1615
{

src/DotNetty.Common/ThreadLocalPool.cs

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -10,7 +10,6 @@ namespace DotNetty.Common
1010
using System.Diagnostics.Contracts;
1111
using System.Runtime.CompilerServices;
1212
using System.Threading;
13-
using Thread = DotNetty.Common.Concurrency.XThread;
1413

1514
public class ThreadLocalPool
1615
{

src/DotNetty.Common/Utilities/HashedWheelTimer.cs

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -27,7 +27,7 @@ public sealed class HashedWheelTimer : ITimer
2727
const int InstanceCountLimit = 64;
2828

2929
readonly Worker worker;
30-
readonly XThread workerThread;
30+
readonly Thread workerThread;
3131
readonly CancellationTokenSource cancellationTokenSource = new CancellationTokenSource();
3232

3333
const int WorkerStateInit = 0;
@@ -98,7 +98,7 @@ public HashedWheelTimer(
9898
tickInterval,
9999
long.MaxValue / this.wheel.Length));
100100
}
101-
this.workerThread = new XThread(st => this.worker.Run());
101+
this.workerThread = new Thread(st => this.worker.Run());
102102

103103
this.maxPendingTimeouts = maxPendingTimeouts;
104104

@@ -187,7 +187,7 @@ public async Task<ISet<ITimeout>> StopAsync()
187187
{
188188
GC.SuppressFinalize(this);
189189

190-
if (XThread.CurrentThread == this.workerThread)
190+
if (Thread.CurrentThread == this.workerThread)
191191
{
192192
throw new InvalidOperationException($"{nameof(HashedWheelTimer)}.stop() cannot be called from timer task.");
193193
}

src/DotNetty.Common/Utilities/ReferenceCountUtil.cs

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,6 @@ namespace DotNetty.Common.Utilities
66
using System;
77
using System.Threading;
88
using DotNetty.Common.Internal.Logging;
9-
using Thread = DotNetty.Common.Concurrency.XThread;
109

1110
public static class ReferenceCountUtil
1211
{

src/DotNetty.Common/Utilities/ThreadExtensions.cs

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,6 @@ namespace DotNetty.Common.Utilities
66
using System;
77
using System.Diagnostics.Contracts;
88
using System.Threading;
9-
using Thread = DotNetty.Common.Concurrency.XThread;
109

1110
public static class ThreadExtensions
1211
{

src/DotNetty.Transport.Libuv/EventLoopGroup.cs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -74,7 +74,7 @@ public EventLoopGroup(int eventLoopCount)
7474
public override IEventExecutor GetNext()
7575
{
7676
// Attempt to select event loop based on thread first
77-
int threadId = XThread.CurrentThread.Id;
77+
int threadId = Thread.CurrentThread.ManagedThreadId;
7878
int i;
7979
for (i = 0; i < this.eventLoops.Length; i++)
8080
{

src/DotNetty.Transport.Libuv/LoopExecutor.cs

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -36,7 +36,7 @@ class LoopExecutor : AbstractScheduledEventExecutor
3636
readonly ThreadLocalPool<WriteRequest> writeRequestPool = new ThreadLocalPool<WriteRequest>(handle => new WriteRequest(handle));
3737
readonly long preciseBreakoutInterval;
3838
readonly IQueue<IRunnable> taskQueue;
39-
readonly XThread thread;
39+
readonly Thread thread;
4040
readonly TaskScheduler scheduler;
4141
readonly ManualResetEventSlim loopRunStart;
4242
readonly TaskCompletionSource terminationCompletionSource;
@@ -80,7 +80,7 @@ public LoopExecutor(IEventLoopGroup parent, string threadName, TimeSpan breakout
8080
{
8181
name = $"{name}({threadName})";
8282
}
83-
this.thread = new XThread(Run) { Name = name };
83+
this.thread = new Thread(Run) { Name = name };
8484
this.loopRunStart = new ManualResetEventSlim(false, 1);
8585
}
8686

@@ -97,7 +97,7 @@ protected void Start()
9797

9898
internal Loop UnsafeLoop => this.loop;
9999

100-
internal int LoopThreadId => this.thread.Id;
100+
internal int LoopThreadId => this.thread.ManagedThreadId;
101101

102102
static void Run(object state)
103103
{
@@ -424,7 +424,7 @@ static IRunnable PollTaskFrom(IQueue<IRunnable> taskQueue) =>
424424

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

427-
public override bool IsInEventLoop(XThread t) => this.thread == t;
427+
public override bool IsInEventLoop(Thread t) => this.thread == t;
428428

429429
void WakeUp(bool inEventLoop)
430430
{

src/DotNetty.Transport/Channels/DefaultChannelPipeline.cs

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -16,7 +16,6 @@ namespace DotNetty.Transport.Channels
1616
using DotNetty.Common.Concurrency;
1717
using DotNetty.Common.Internal.Logging;
1818
using DotNetty.Common.Utilities;
19-
using Thread = DotNetty.Common.Concurrency.XThread;
2019

2120
public class DefaultChannelPipeline : IChannelPipeline
2221
{

src/DotNetty.Transport/Channels/Embedded/EmbeddedEventLoop.cs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -5,10 +5,10 @@ namespace DotNetty.Transport.Channels.Embedded
55
{
66
using System;
77
using System.Collections.Generic;
8+
using System.Threading;
89
using System.Threading.Tasks;
910
using DotNetty.Common;
1011
using DotNetty.Common.Concurrency;
11-
using Thread = DotNetty.Common.Concurrency.XThread;
1212

1313
sealed class EmbeddedEventLoop : AbstractScheduledEventExecutor, IEventLoop
1414
{

test/DotNetty.Common.Tests/ThreadLocalPoolTest.cs

Lines changed: 2 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -23,14 +23,13 @@ public void ThreadCanBeCollectedEvenIfHandledObjectIsReferencedTest()
2323
ThreadLocalPool<HandledObject> pool = NewPool(1024);
2424
HandledObject reference = null;
2525
WeakReference<Thread> threadRef = null;
26-
WeakReference<XThread> xThreadRef = null;
2726

2827
var thread1 = new Thread(() =>
2928
{
3029
//Don't know the reason, but thread2 will not be collected without wrapped with thread1
3130
var thread2 = new Thread(() =>
3231
{
33-
Volatile.Write(ref xThreadRef, new WeakReference<XThread>(XThread.CurrentThread));
32+
Volatile.Write(ref threadRef, new WeakReference<Thread>(Thread.CurrentThread));
3433
HandledObject data = pool.Take();
3534
// Store a reference to the HandledObject to ensure it is not collected when the run method finish.
3635
Volatile.Write(ref reference, data);
@@ -39,7 +38,6 @@ public void ThreadCanBeCollectedEvenIfHandledObjectIsReferencedTest()
3938
thread2.Start();
4039
thread2.Join();
4140
Assert.True(Volatile.Read(ref threadRef)?.TryGetTarget(out _));
42-
Assert.True(Volatile.Read(ref xThreadRef)?.TryGetTarget(out _));
4341

4442
GC.KeepAlive(thread2);
4543
// Null out so it can be collected.
@@ -53,12 +51,11 @@ public void ThreadCanBeCollectedEvenIfHandledObjectIsReferencedTest()
5351
GC.Collect(GC.MaxGeneration, GCCollectionMode.Forced, true);
5452
GC.WaitForPendingFinalizers();
5553

56-
if (Volatile.Read(ref threadRef)?.TryGetTarget(out _) == true || Volatile.Read(ref xThreadRef)?.TryGetTarget(out _) == true)
54+
if (Volatile.Read(ref threadRef)?.TryGetTarget(out _) == true || Volatile.Read(ref threadRef)?.TryGetTarget(out _) == true)
5755
Thread.Sleep(100);
5856
}
5957

6058
Assert.False(Volatile.Read(ref threadRef)?.TryGetTarget(out _));
61-
Assert.False(Volatile.Read(ref xThreadRef)?.TryGetTarget(out _));
6259

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

0 commit comments

Comments
 (0)