00001
00002
00003
00004
00005
00006
00007
00008
00009 #ifndef __libutilxx__sella__util__TaskQueue_H__
00010 #define __libutilxx__sella__util__TaskQueue_H__
00011
00012 #include "../../common.h"
00013 #include "Task.h"
00014 #include "Log.h"
00015
00016 #include <vector>
00017 #include <chrono>
00018
00019 namespace sella {
00020 namespace util {
00021 class TaskQueue;
00022 }
00023 }
00024
00025 class sella::util::TaskQueue {
00026 public:
00027 typedef std::shared_ptr<TaskQueue> shared;
00028
00029 public:
00030 static const size_t DefaultMinimumCapacity = 16;
00031
00032 public:
00033 TaskQueue(const size_t capacity = DefaultMinimumCapacity);
00034 TaskQueue(Log::shared log, const size_t capacity = DefaultMinimumCapacity);
00035 TaskQueue(const TaskQueue &other) = delete;
00036 virtual ~TaskQueue();
00037 TaskQueue& operator=(const TaskQueue &other) = delete;
00038
00039 size_t size(void) const;
00040 bool empty(void) const;
00041 void clear(void);
00042
00043 Task::shared top(void) const;
00044 void push(Task::shared &task);
00045 void push(Task::shared &task, const std::chrono::system_clock::duration &delay, int priority = 0);
00046 void push(Task::shared &task, const std::chrono::system_clock::time_point &time, int priority = 0);
00047 void push(Task::shared &task, time_t sec, suseconds_t usec = 0, int priority = 0);
00048 void push(Task::shared &task, timeval &tv, int priority = 0);
00049 bool repush(Task::shared &task, const std::chrono::system_clock::duration &delay, int priority = 0, bool strict = false);
00050 bool repush(Task::shared &task, const std::chrono::system_clock::time_point &time, int priority = 0, bool strict = false);
00051 bool repush(Task::shared &task, time_t sec, suseconds_t usec = 0, int priority = 0, bool strict = false);
00052 bool repush(Task::shared &task, timeval &tv, int priority = 0, bool strict = false);
00053 void pop(void);
00054 bool erase(Task::shared &task, bool firstonly = true);
00055 bool erase(void *object);
00056
00057 size_t capacity(void) const;
00058 void reserve(size_t capacity);
00059 void print(void) const;
00060 void setLog(Log::shared log);
00061
00062 protected:
00063 Log::shared libutilxx__log;
00064 std::vector<Task::shared> heap;
00065 };
00066
00067 #endif
00068
00069
00070
00071