Unverified Commit 60ac3b26 authored by kladko's avatar kladko

SKALE-4586 Add Agent class

parent c45204e1
...@@ -71,7 +71,7 @@ bin_PROGRAMS = sgxwallet testw sgx_util ...@@ -71,7 +71,7 @@ bin_PROGRAMS = sgxwallet testw sgx_util
COMMON_SRC = SGXException.cpp ExitHandler.cpp zmq_src/ZMQClient.cpp zmq_src/RspMessage.cpp zmq_src/ReqMessage.cpp \ COMMON_SRC = SGXException.cpp ExitHandler.cpp zmq_src/ZMQClient.cpp zmq_src/RspMessage.cpp zmq_src/ReqMessage.cpp \
zmq_src/ZMQMessage.cpp zmq_src/ZMQServer.cpp ExitRequestedException.cpp \ zmq_src/ZMQMessage.cpp zmq_src/ZMQServer.cpp zmq_src/Agent.cpp ExitRequestedException.cpp \
InvalidStateException.cpp Exception.cpp InvalidArgumentException.cpp Log.cpp TECrypto.cpp \ InvalidStateException.cpp Exception.cpp InvalidArgumentException.cpp Log.cpp TECrypto.cpp \
SGXWalletServer.cpp SGXRegistrationServer.cpp CSRManagerServer.cpp BLSCrypto.cpp CryptoTools.cpp \ SGXWalletServer.cpp SGXRegistrationServer.cpp CSRManagerServer.cpp BLSCrypto.cpp CryptoTools.cpp \
DKGCrypto.cpp ServerInit.cpp BLSPrivateKeyShareSGX.cpp LevelDB.cpp ServerDataChecker.cpp SEKManager.cpp \ DKGCrypto.cpp ServerInit.cpp BLSPrivateKeyShareSGX.cpp LevelDB.cpp ServerDataChecker.cpp SEKManager.cpp \
......
/*
Copyright (C) 2021 SKALE Labs
This file is part of skale-consensus.
skale-consensus is free software: you can redistribute it and/or modify
it under the terms of the GNU Affero General Public License as published
by the Free Software Foundation, either version 3 of the License, or
(at your option) any later version.
skale-consensus is distributed in the hope that it will be useful,
but WITHOUT ANY WARRANTY; without even the implied warranty of
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
GNU Affero General Public License for more details.
You should have received a copy of the GNU Affero General Public License
along with skale-consensus. If not, see <https://www.gnu.org/licenses/>.
@file Agent.cpp
@author Stan Kladko
@date 2021
*/
#include "Agent.h"
void Agent::notifyAllConditionVariables() {
messageCond.notify_all();
queueCond.notify_all();
}
Agent::Agent() : startedRun(false) {};
void Agent::waitOnGlobalStartBarrier() {
unique_lock<mutex> mlock(queueMutex);
while (!startedRun) {
queueCond.wait(mlock);
}
}
Agent::~Agent() {
}
void Agent::releaseGlobalStartBarrier() {
if (startedRun.exchange(true)) {
return;
}
lock_guard<mutex> lock(queueMutex);
queueCond.notify_all();
}
/*
Copyright (C) 2021 SKALE Labs
This file is part of skale-consensus.
skale-consensus is free software: you can redistribute it and/or modify
it under the terms of the GNU Affero General Public License as published
by the Free Software Foundation, either version 3 of the License, or
(at your option) any later version.
skale-consensus is distributed in the hope that it will be useful,
but WITHOUT ANY WARRANTY; without even the implied warranty of
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
GNU Affero General Public License for more details.
You should have received a copy of the GNU Affero General Public License
along with skale-consensus. If not, see <https://www.gnu.org/licenses/>.
@file Agent.h
@author Stan Kladko
@date 2021
*/
#pragma once
#include <condition_variable>
#include <mutex>
#include <atomic>
using namespace std;
class Agent {
protected:
atomic_bool startedRun;
mutex messageMutex;
condition_variable messageCond;
condition_variable queueCond;
mutex queueMutex;
recursive_mutex m;
public:
Agent();
void notifyAllConditionVariables();
virtual ~Agent();
void releaseGlobalStartBarrier();
void waitOnGlobalStartBarrier();
recursive_mutex& getMainMutex() { return m; }
};
...@@ -35,10 +35,12 @@ ...@@ -35,10 +35,12 @@
#include <zmq.hpp> #include <zmq.hpp>
#include "zhelpers.hpp" #include "zhelpers.hpp"
#include "Agent.h"
using namespace std; using namespace std;
class ZMQServer { class ZMQServer : Agent{
uint64_t workerThreads; uint64_t workerThreads;
......
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