Unverified Commit d4e26311 authored by kladko's avatar kladko

SKALE-4586 Added Thread Pool

parent 4066708d
1.78.0 1.83.0
\ No newline at end of file \ No newline at end of file
...@@ -24,17 +24,14 @@ ...@@ -24,17 +24,14 @@
#include "Agent.h" #include "Agent.h"
void Agent::notifyAllConditionVariables() {
messageCond.notify_all();
queueCond.notify_all();
}
Agent::Agent() : startedWorkers(false) {}; Agent::Agent() : startedWorkers(false) {};
void Agent::waitOnGlobalStartBarrier() { void Agent::waitOnGlobalStartBarrier() {
unique_lock<mutex> mlock(queueMutex); unique_lock<mutex> lock(startMutex);
while (!startedWorkers) { while (!startedWorkers) {
queueCond.wait(mlock); // wait until notified to start running
startCond.wait(lock);
} }
} }
...@@ -49,7 +46,7 @@ void Agent::releaseWorkers() { ...@@ -49,7 +46,7 @@ void Agent::releaseWorkers() {
return; return;
} }
lock_guard<mutex> lock(queueMutex); lock_guard<mutex> lock(startMutex);
queueCond.notify_all(); startCond.notify_all();
} }
...@@ -38,8 +38,8 @@ protected: ...@@ -38,8 +38,8 @@ protected:
mutex messageMutex; mutex messageMutex;
condition_variable messageCond; condition_variable messageCond;
condition_variable queueCond; condition_variable startCond;
mutex queueMutex; mutex startMutex;
recursive_mutex m; recursive_mutex m;
...@@ -48,8 +48,6 @@ public: ...@@ -48,8 +48,6 @@ public:
Agent(); Agent();
void notifyAllConditionVariables();
virtual ~Agent(); virtual ~Agent();
void releaseWorkers(); void releaseWorkers();
......
...@@ -260,11 +260,12 @@ void ZMQServer::doOneServerLoop() { ...@@ -260,11 +260,12 @@ void ZMQServer::doOneServerLoop() {
} }
} }
void ZMQServer::workerThreadMessageProcessLoop(ZMQServer* _agent ) { void ZMQServer::workerThreadMessageProcessLoop(ZMQServer* _agent ) {
CHECK_STATE(_agent); CHECK_STATE(_agent);
_agent->waitOnGlobalStartBarrier(); _agent->waitOnGlobalStartBarrier();
// do work forever until told to exit
while (!isExitRequested) { while (!isExitRequested) {
sleep(100); sleep(1000);
cerr << "WORKER LOOP" << endl;
} }
} }
\ No newline at end of file
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment