Added TaskQueue

master
Harald Wolff 2019-12-16 09:23:27 +01:00
parent 31064d8175
commit cfe09dc39d
2 changed files with 45 additions and 0 deletions

View File

@ -131,6 +131,7 @@
<Compile Include="ByteArrayExtensions.cs" />
<Compile Include="Promise.cs" />
<Compile Include="test\PromiseTests.cs" />
<Compile Include="threads\TaskQueue.cs" />
</ItemGroup>
<ItemGroup>
<Folder Include="odb\" />

View File

@ -0,0 +1,44 @@
// /**
// * File: TaskQueue.cs
// * Author: haraldwolff
// *
// * This file and it's content is copyrighted by the Author and / or copyright holder.
// * Any use wihtout proper permission is illegal and may lead to legal actions.
// *
// *
// **/
using System;
using ln.types.btree;
using System.Linq;
namespace ln.types.threads
{
public class TaskQueue
{
BTreeValueList<int, Action> queue = new BTreeValueList<int, Action>();
public TaskQueue()
{
}
public bool Empty => queue.Keys.Count() == 0;
public void Enqueue(Action action) => Enqueue(0, action);
public void Enqueue(int priority,Action action)
{
lock (queue)
{
queue.TryRemove(priority, action);
queue.Add(priority, action);
}
}
public Action Dequeue()
{
lock (queue)
{
return queue.Shift();
}
}
}
}