2019-11-19 23:03:20 -05:00
|
|
|
#pragma once
|
|
|
|
#include "fastlock.h"
|
|
|
|
#include <vector>
|
2019-11-28 19:00:51 -05:00
|
|
|
#include <deque>
|
2019-11-19 23:03:20 -05:00
|
|
|
#include <mutex>
|
|
|
|
#include <thread>
|
|
|
|
#include <condition_variable>
|
|
|
|
#include <atomic>
|
|
|
|
#include <functional>
|
|
|
|
|
|
|
|
class AsyncWorkQueue
|
|
|
|
{
|
|
|
|
struct WorkItem
|
|
|
|
{
|
|
|
|
WorkItem(std::function<void()> &&fnAsync)
|
|
|
|
: fnAsync(std::move(fnAsync))
|
|
|
|
{}
|
|
|
|
|
|
|
|
WorkItem(WorkItem&&) = default;
|
|
|
|
std::function<void()> fnAsync;
|
|
|
|
};
|
|
|
|
std::vector<std::thread> m_vecthreads;
|
2019-11-23 19:00:27 -05:00
|
|
|
std::vector<struct redisServerThreadVars*> m_vecpthreadVars;
|
2019-11-28 19:00:51 -05:00
|
|
|
std::deque<WorkItem> m_workqueue;
|
2019-11-19 23:03:20 -05:00
|
|
|
std::mutex m_mutex;
|
|
|
|
std::condition_variable m_cvWakeup;
|
|
|
|
std::atomic<bool> m_fQuitting { false };
|
|
|
|
|
|
|
|
void WorkerThreadMain();
|
|
|
|
public:
|
|
|
|
AsyncWorkQueue(int nthreads);
|
|
|
|
~AsyncWorkQueue();
|
|
|
|
|
2019-11-28 19:00:51 -05:00
|
|
|
void AddWorkFunction(std::function<void()> &&fnAsync, bool fHiPri = false);
|
2019-11-23 19:00:27 -05:00
|
|
|
bool removeClientAsyncWrites(struct client *c);
|
2019-11-19 23:03:20 -05:00
|
|
|
|
2020-07-10 00:17:39 +00:00
|
|
|
void shutdown();
|
|
|
|
|
2019-11-19 23:03:20 -05:00
|
|
|
void abandonThreads();
|
|
|
|
};
|