5 #ifndef JODA_THREADMANAGER_H
6 #define JODA_THREADMANAGER_H
9 #include <glog/logging.h>
13 #include <unordered_map>
17 #define JODA_THREAD_POLLING_TIME 500ms
28 template <
class queue_t>
30 std::vector<size_t> &readerIds, queue_t &queue,
32 std::pair<size_t, size_t> prevStats;
34 std::pair<size_t, size_t> stats = queue->getStatistics();
35 std::pair<size_t, size_t> currStats = stats;
36 currStats.first -= prevStats.first;
37 currStats.second -= prevStats.second;
40 for (
const auto &
id : writerIds) {
41 i += users[id]->getUsedThreads();
44 for (
const auto &
id : readerIds) {
45 o += users[id]->getUsedThreads();
47 DLOG(INFO) <<
"QUEUE I/O: " << currStats.first <<
"/" << currStats.second
49 <<
"Threads I/O: " << i <<
"/" << o;
50 using namespace std::chrono_literals;
57 void recalculateThreads();
58 size_t maxThreads = 1;
59 size_t usedThreads()
const;
60 size_t reservedThreads()
const;
61 size_t availableThreads()
const;
62 std::unordered_map<size_t, IThreadUser *> users;
#define JODA_THREAD_POLLING_TIME
Definition: ThreadManager.h:17
ThreadManager g_ThreadManagerInstance
Definition: ThreadManager.cpp:8
Definition: IThreadUser.h:13
Definition: ThreadManager.h:19
size_t registerThreadUser(IThreadUser *user)
Definition: ThreadManager.cpp:21
void balanceQueue(std::vector< size_t > &writerIds, std::vector< size_t > &readerIds, queue_t &queue, bool &stop)
Definition: ThreadManager.h:29
void unregisterThreadUser(size_t id)
Definition: ThreadManager.cpp:30
void setMaxThreads(size_t maxThreads)
Definition: ThreadManager.cpp:12
size_t getMaxThreads() const
Definition: ThreadManager.cpp:10