Added TaskQueue
parent
31064d8175
commit
cfe09dc39d
|
@ -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\" />
|
||||
|
|
|
@ -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();
|
||||
}
|
||||
}
|
||||
|
||||
}
|
||||
}
|
Loading…
Reference in New Issue