Skip to content

Commit

Permalink
make DedicatedThreadPool.QueueUserWorkItem<T> generic (#6156)
Browse files Browse the repository at this point in the history
* make `DedicatedThreadPool.QueueUserWorkItem<T>` generic

Done to avoid boxing allocations

* make adding methods generic
  • Loading branch information
Aaronontheweb committed Oct 8, 2022
1 parent 18aae3b commit 2131146
Showing 1 changed file with 3 additions and 3 deletions.
6 changes: 3 additions & 3 deletions src/core/Akka/Helios.Concurrency.DedicatedThreadPool.cs
Expand Up @@ -226,7 +226,7 @@ private void ReleaseWorker()
}
}

private struct RequestWorkerTask : IRunnable
private readonly struct RequestWorkerTask : IRunnable
{
private readonly DedicatedThreadPoolTaskScheduler _scheduler;

Expand Down Expand Up @@ -312,7 +312,7 @@ public DedicatedThreadPool(DedicatedThreadPoolSettings settings)
/// This exception is thrown if the given <paramref name="work"/> item is undefined.
/// </exception>
/// <returns>TBD</returns>
public bool QueueUserWorkItem(IRunnable work)
public bool QueueUserWorkItem<T>(T work) where T:IRunnable
{
if (work == null)
throw new ArgumentNullException(nameof(work), "Work item cannot be null.");
Expand Down Expand Up @@ -416,7 +416,7 @@ public bool IsAddingCompleted
get { return Volatile.Read(ref _isAddingCompleted) == CompletedState; }
}

public bool TryAdd(IRunnable work)
public bool TryAdd<T>(T work) where T:IRunnable
{
// If TryAdd returns true, it's guaranteed the work item will be executed.
// If it returns false, it's also guaranteed the work item won't be executed.
Expand Down

0 comments on commit 2131146

Please sign in to comment.