Skip to content
Permalink
Browse files

Workaround for CoreFx/#30781 (Fixes #4505) (#4736)

  • Loading branch information...
ReubenBond authored and benjaminpetit committed Jul 5, 2018
1 parent b256888 commit 56ae21d0b40c8a0835a6eb93aeb5e4bc581ecf1a
Showing with 21 additions and 2 deletions.
  1. +21 −2 src/Orleans.Runtime/Scheduler/WorkQueue.cs
@@ -2,6 +2,7 @@

using System;
using System.Collections.Concurrent;
using System.Runtime.InteropServices;
using System.Text;
using System.Threading;

@@ -20,8 +21,8 @@ internal class WorkQueue

internal WorkQueue()
{
mainQueue = new BlockingCollection<IWorkItem>(new ConcurrentBag<IWorkItem>());
systemQueue = new BlockingCollection<IWorkItem>(new ConcurrentBag<IWorkItem>());
mainQueue = CreateWorkQueue();
systemQueue = CreateWorkQueue();
queueArray = new BlockingCollection<IWorkItem>[] { systemQueue, mainQueue };

if (!StatisticsCollector.CollectShedulerQueuesStats) return;
@@ -33,6 +34,24 @@ internal WorkQueue()
systemQueueTracking.OnStartExecution();
tasksQueueTracking.OnStartExecution();
}

private static BlockingCollection<IWorkItem> CreateWorkQueue()
{
return new BlockingCollection<IWorkItem>(CreateUnderlyingCollection());

// As a workaround for https://github.com/dotnet/corefx/issues/30781,
// this function uses a ConcurrentQueue when running on .NET Core.
// In order to preserve behavior on .NET Framework, however, this
// function will return a ConcurrentBag when not running on .NET Core.
// See https://github.com/dotnet/orleans/issues/4505
IProducerConsumerCollection<IWorkItem> CreateUnderlyingCollection()
{
if (IsCoreFramework()) return new ConcurrentQueue<IWorkItem>();
return new ConcurrentBag<IWorkItem>();
}

bool IsCoreFramework() => RuntimeInformation.FrameworkDescription.StartsWith(".NET Core");
}

public void Add(IWorkItem workItem)
{

0 comments on commit 56ae21d

Please sign in to comment.
You can’t perform that action at this time.