-
-
Notifications
You must be signed in to change notification settings - Fork 111
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
13 changed files
with
181 additions
and
53 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,13 @@ | ||
#if NETSTANDARD2_0 || NETSTANDARD2_1 | ||
|
||
namespace System.Threading; | ||
|
||
internal static class CancellationTokenExtensions | ||
{ | ||
public static CancellationTokenRegistration UnsafeRegister(this CancellationToken cancellationToken, Action<object?> callback, object? state) | ||
{ | ||
return cancellationToken.Register(callback, state); | ||
} | ||
} | ||
|
||
#endif |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,24 @@ | ||
using System.Runtime.CompilerServices; | ||
|
||
#if !NET6_0_OR_GREATER | ||
namespace System.Runtime.InteropServices; | ||
|
||
internal static class CollectionsMarshal | ||
{ | ||
#pragma warning disable CS8618 | ||
#pragma warning disable CS0169 | ||
#pragma warning disable CS0649 | ||
|
||
class ListDummy<T> | ||
{ | ||
public T[] Items; | ||
int size; | ||
int version; | ||
} | ||
|
||
internal static Span<T> AsSpan<T>(List<T> list) | ||
{ | ||
return Unsafe.As<ListDummy<T>>(list).Items.AsSpan(0, list.Count); | ||
} | ||
} | ||
#endif |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,19 @@ | ||
#if NETSTANDARD2_0 || NETSTANDARD2_1 | ||
|
||
namespace System.Diagnostics | ||
{ | ||
/// <summary> | ||
/// Types and Methods attributed with StackTraceHidden will be omitted from the stack trace text shown in StackTrace.ToString() | ||
/// and Exception.StackTrace | ||
/// </summary> | ||
[AttributeUsage(AttributeTargets.Class | AttributeTargets.Method | AttributeTargets.Constructor | AttributeTargets.Struct, Inherited = false)] | ||
internal sealed class StackTraceHiddenAttribute : Attribute | ||
{ | ||
/// <summary> | ||
/// Initializes a new instance of the <see cref="StackTraceHiddenAttribute"/> class. | ||
/// </summary> | ||
public StackTraceHiddenAttribute() { } | ||
} | ||
} | ||
|
||
#endif |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,33 @@ | ||
#if NETSTANDARD2_0 || NETSTANDARD2_1 | ||
|
||
namespace R3; | ||
|
||
internal static class TaskExtensions | ||
{ | ||
internal static Task<T> WaitAsync<T>(this Task<T> task, CancellationToken cancellationToken) | ||
{ | ||
var tcs = new TaskCompletionSource<T>(); | ||
var registration = cancellationToken.Register(() => tcs.TrySetCanceled(cancellationToken)); | ||
|
||
task.ContinueWith(t => | ||
{ | ||
registration.Dispose(); | ||
if (t.IsFaulted) | ||
{ | ||
tcs.TrySetException(t.Exception!.InnerExceptions); | ||
} | ||
else if (t.IsCanceled) | ||
{ | ||
tcs.TrySetCanceled(cancellationToken); | ||
} | ||
else | ||
{ | ||
tcs.TrySetResult(t.Result); | ||
} | ||
}, TaskScheduler.Default); | ||
|
||
return tcs.Task; | ||
} | ||
} | ||
|
||
#endif |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,27 @@ | ||
#if NETSTANDARD2_0 || NETSTANDARD2_1 | ||
|
||
namespace R3 // namespace priority | ||
{ | ||
public interface IThreadPoolWorkItem | ||
{ | ||
void Execute(); | ||
} | ||
|
||
public static class ThreadPool | ||
{ | ||
static readonly WaitCallback waitCallback = Execute; | ||
|
||
public static bool UnsafeQueueUserWorkItem(IThreadPoolWorkItem callBack, bool preferLocal) | ||
{ | ||
return global::System.Threading.ThreadPool.UnsafeQueueUserWorkItem(waitCallback, callBack); | ||
} | ||
|
||
static void Execute(object? state) | ||
{ | ||
var workItem = (IThreadPoolWorkItem)state!; | ||
workItem.Execute(); | ||
} | ||
} | ||
} | ||
|
||
#endif |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,4 +1,4 @@ | ||
using System.Xml.Linq; | ||
using System.Collections; | ||
|
||
namespace R3; | ||
|
||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters