Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[*] Refactor #77

Merged
merged 4 commits into from
Nov 30, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
153 changes: 44 additions & 109 deletions PowerThreadPool/Core/PowerThreadPool.QueueWorkItem.cs

Large diffs are not rendered by default.

3 changes: 3 additions & 0 deletions PowerThreadPool/Core/PowerThreadPool.cs
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,9 @@

namespace PowerThreadPool
{
/// <summary>
/// A comprehensive and efficient lock-free thread pool with granular work control, flexible concurrency, and robust error handling, alongside an easy-to-use API for diverse work submissions.
/// </summary>
public partial class PowerPool : IDisposable
{
private bool _disposed = false;
Expand Down
72 changes: 59 additions & 13 deletions PowerThreadPool/Helpers/DelegateHelper.cs
Original file line number Diff line number Diff line change
Expand Up @@ -6,19 +6,30 @@ internal static class DelegateHelper<TResult>
{
internal static Func<object[], TResult> ToNormalFunc(Func<TResult> function)
{
TResult func(object[] param) { return function(); }
TResult func(object[] param)
{
return function();
}
return func;
}

internal static Func<object[], TResult> ToNormalFunc(Action action)
{
TResult func() { action(); return default; }
TResult func()
{
action();
return default;
}
return DelegateHelper<TResult>.ToNormalFunc(func);
}

internal static Func<object[], TResult> ToNormalFunc(Action<object[]> action, object[] param)
{
TResult func(object[] p) { action(param); return default; }
TResult func(object[] p)
{
action(param);
return default;
}
return func;
}
}
Expand All @@ -27,13 +38,20 @@ internal static class DelegateHelper<T1, TResult>
{
internal static Func<object[], TResult> ToNormalFunc(Action<T1> action, T1 param1)
{
TResult func(T1 p) { action(p); return default; }
TResult func(T1 p)
{
action(p);
return default;
}
return DelegateHelper<T1, TResult>.ToNormalFunc(func, param1);
}

internal static Func<object[], TResult> ToNormalFunc(Func<T1, TResult> function, T1 param1)
{
TResult func() { return function(param1); }
TResult func()
{
return function(param1);
}
return DelegateHelper<TResult>.ToNormalFunc(func);
}
}
Expand All @@ -42,13 +60,20 @@ internal static class DelegateHelper<T1, T2, TResult>
{
internal static Func<object[], TResult> ToNormalFunc(Action<T1, T2> action, T1 param1, T2 param2)
{
TResult func(T1 p1, T2 p2) { action(p1, p2); return default; }
TResult func(T1 p1, T2 p2)
{
action(p1, p2);
return default;
}
return DelegateHelper<T1, T2, TResult>.ToNormalFunc(func, param1, param2);
}

internal static Func<object[], TResult> ToNormalFunc(Func<T1, T2, TResult> function, T1 param1, T2 param2)
{
TResult func() { return function(param1, param2); }
TResult func()
{
return function(param1, param2);
}
return DelegateHelper<TResult>.ToNormalFunc(func);
}
}
Expand All @@ -57,13 +82,20 @@ internal static class DelegateHelper<T1, T2, T3, TResult>
{
internal static Func<object[], TResult> ToNormalFunc(Action<T1, T2, T3> action, T1 param1, T2 param2, T3 param3)
{
TResult func(T1 p1, T2 p2, T3 p3) { action(p1, p2, p3); return default; }
TResult func(T1 p1, T2 p2, T3 p3)
{
action(p1, p2, p3);
return default;
}
return DelegateHelper<T1, T2, T3, TResult>.ToNormalFunc(func, param1, param2, param3);
}

internal static Func<object[], TResult> ToNormalFunc(Func<T1, T2, T3, TResult> function, T1 param1, T2 param2, T3 param3)
{
TResult func() { return function(param1, param2, param3); }
TResult func()
{
return function(param1, param2, param3);
}
return DelegateHelper<TResult>.ToNormalFunc(func);
}
}
Expand All @@ -72,13 +104,20 @@ internal static class DelegateHelper<T1, T2, T3, T4, TResult>
{
internal static Func<object[], TResult> ToNormalFunc(Action<T1, T2, T3, T4> action, T1 param1, T2 param2, T3 param3, T4 param4)
{
TResult func(T1 p1, T2 p2, T3 p3, T4 p4) { action(p1, p2, p3, p4); return default; }
TResult func(T1 p1, T2 p2, T3 p3, T4 p4)
{
action(p1, p2, p3, p4);
return default;
}
return DelegateHelper<T1, T2, T3, T4, TResult>.ToNormalFunc(func, param1, param2, param3, param4);
}

internal static Func<object[], TResult> ToNormalFunc(Func<T1, T2, T3, T4, TResult> function, T1 param1, T2 param2, T3 param3, T4 param4)
{
TResult func() { return function(param1, param2, param3, param4); }
TResult func()
{
return function(param1, param2, param3, param4);
}
return DelegateHelper<TResult>.ToNormalFunc(func);
}
}
Expand All @@ -87,13 +126,20 @@ internal static class DelegateHelper<T1, T2, T3, T4, T5, TResult>
{
internal static Func<object[], TResult> ToNormalFunc(Action<T1, T2, T3, T4, T5> action, T1 param1, T2 param2, T3 param3, T4 param4, T5 param5)
{
TResult func(T1 p1, T2 p2, T3 p3, T4 p4, T5 p5) { action(p1, p2, p3, p4, p5); return default; }
TResult func(T1 p1, T2 p2, T3 p3, T4 p4, T5 p5)
{
action(p1, p2, p3, p4, p5);
return default;
}
return DelegateHelper<T1, T2, T3, T4, T5, TResult>.ToNormalFunc(func, param1, param2, param3, param4, param5);
}

internal static Func<object[], TResult> ToNormalFunc(Func<T1, T2, T3, T4, T5, TResult> function, T1 param1, T2 param2, T3 param3, T4 param4, T5 param5)
{
TResult func() { return function(param1, param2, param3, param4, param5); }
TResult func()
{
return function(param1, param2, param3, param4, param5);
}
return DelegateHelper<TResult>.ToNormalFunc(func);
}
}
Expand Down
10 changes: 5 additions & 5 deletions PowerThreadPool/Options/PowerPoolOption.cs
Original file line number Diff line number Diff line change
Expand Up @@ -4,13 +4,13 @@

namespace PowerThreadPool.Options
{
public enum QueueType { FIFO, LIFO }
public enum QueueType
{
FIFO,
LIFO
}
public class PowerPoolOption
{
public PowerPoolOption()
{
}

/// <summary>
/// The maximum number of threads that the thread pool can support.
/// </summary>
Expand Down
14 changes: 12 additions & 2 deletions PowerThreadPool/Options/RetryOption.cs
Original file line number Diff line number Diff line change
@@ -1,7 +1,17 @@
namespace PowerThreadPool.Options
{
public enum RetryBehavior { ImmediateRetry, Requeue }
public enum RetryPolicy { Limited, Unlimited }
public enum RetryBehavior
{
ImmediateRetry,
Requeue
}

public enum RetryPolicy
{
Limited,
Unlimited
}

public class RetryOption
{
/// <summary>
Expand Down
4 changes: 0 additions & 4 deletions PowerThreadPool/Options/TimeoutOption.cs
Original file line number Diff line number Diff line change
Expand Up @@ -2,10 +2,6 @@
{
public class TimeoutOption
{
public TimeoutOption()
{
}

/// <summary>
/// The maximum amount of time (ms).
/// </summary>
Expand Down
7 changes: 0 additions & 7 deletions PowerThreadPool/Options/WorkOption.cs
Original file line number Diff line number Diff line change
Expand Up @@ -7,10 +7,6 @@ namespace PowerThreadPool.Options
{
public class WorkOption<TResult>
{
public WorkOption()
{
}

/// <summary>
/// The custom work ID. If set to null, the thread pool will use a Guid as the work ID.
/// </summary>
Expand Down Expand Up @@ -70,8 +66,5 @@ public WorkOption()

public class WorkOption : WorkOption<object>
{
public WorkOption()
{
}
}
}
Loading