ln.threading/ln.threading/TaskQueue.cs

45 lines
998 B
C#

// /**
// * 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.collections;
using System.Linq;
namespace ln.threading
{
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();
}
}
}
}