Skip to content
Projects
Groups
Snippets
Help
Loading...
Help
Submit feedback
Contribute to GitLab
Sign in
Toggle navigation
S
sgxwallet
Project
Project
Details
Activity
Releases
Cycle Analytics
Repository
Repository
Files
Commits
Branches
Tags
Contributors
Graph
Compare
Charts
Issues
0
Issues
0
List
Board
Labels
Milestones
Merge Requests
0
Merge Requests
0
CI / CD
CI / CD
Pipelines
Jobs
Schedules
Charts
Wiki
Wiki
Snippets
Snippets
Members
Members
Collapse sidebar
Close sidebar
Activity
Graph
Charts
Create a new issue
Jobs
Commits
Issue Boards
Open sidebar
董子豪
sgxwallet
Commits
ca858196
Unverified
Commit
ca858196
authored
Sep 07, 2021
by
kladko
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
SKALE-4586 Added Thread Pool
parent
bc2f6e44
Changes
3
Hide whitespace changes
Inline
Side-by-side
Showing
3 changed files
with
135 additions
and
1 deletion
+135
-1
Makefile.am
Makefile.am
+1
-1
WorkerThreadPool.cpp
zmq_src/WorkerThreadPool.cpp
+71
-0
WorkerThreadPool.h
zmq_src/WorkerThreadPool.h
+63
-0
No files found.
Makefile.am
View file @
ca858196
...
...
@@ -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
\
zmq_src/ZMQMessage.cpp zmq_src/ZMQServer.cpp zmq_src/Agent.cpp ExitRequestedException.cpp
\
zmq_src/ZMQMessage.cpp zmq_src/ZMQServer.cpp zmq_src/Agent.cpp
zmq_src/WorkerThreadPool.cpp
ExitRequestedException.cpp
\
InvalidStateException.cpp Exception.cpp InvalidArgumentException.cpp Log.cpp TECrypto.cpp
\
SGXWalletServer.cpp SGXRegistrationServer.cpp CSRManagerServer.cpp BLSCrypto.cpp CryptoTools.cpp
\
DKGCrypto.cpp ServerInit.cpp BLSPrivateKeyShareSGX.cpp LevelDB.cpp ServerDataChecker.cpp SEKManager.cpp
\
...
...
zmq_src/WorkerThreadPool.cpp
0 → 100644
View file @
ca858196
/*
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 WorkerThreadPool.cpp
@author Stan Kladko
@date 2021
*/
#include "common.h"
#include "third_party/spdlog/spdlog.h"
#include "WorkerThreadPool.h"
void
WorkerThreadPool
::
startService
()
{
lock_guard
<
recursive_mutex
>
lock
(
threadPoolMutex
);
CHECK_STATE
(
!
started
.
exchange
(
true
))
for
(
uint64_t
i
=
0
;
i
<
(
uint64_t
)
numThreads
;
i
++
)
{
createThread
(
i
);
}
}
WorkerThreadPool
::
WorkerThreadPool
(
uint64_t
_numThreads
,
Agent
*
_agent
)
:
started
(
false
),
joined
(
false
)
{
CHECK_STATE
(
_numThreads
>
0
);
CHECK_STATE
(
_agent
);
spdlog
::
info
(
"Started thread pool. Threads count:"
+
to_string
(
_numThreads
));
this
->
agent
=
_agent
;
this
->
numThreads
=
_numThreads
;;
}
void
WorkerThreadPool
::
joinAll
()
{
if
(
joined
)
return
;
lock_guard
<
recursive_mutex
>
lock
(
threadPoolMutex
);
joined
=
true
;
for
(
auto
&&
thread
:
threadpool
)
{
if
(
thread
->
joinable
())
thread
->
join
();
CHECK_STATE
(
!
thread
->
joinable
());
}
}
bool
WorkerThreadPool
::
isJoined
()
const
{
return
joined
;
}
WorkerThreadPool
::~
WorkerThreadPool
(){
}
zmq_src/WorkerThreadPool.h
0 → 100644
View file @
ca858196
/*
Copyright (C) 2018-2019 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 WorkerThreadPool.h
@author Stan Kladko
@date 2018
*/
#pragma once
#include <vector>
#include <atomic>
#include <thread>
#include "Agent.h"
class
WorkerThreadPool
{
atomic_bool
started
;
virtual
void
createThread
(
uint64_t
threadNumber
)
=
0
;
protected
:
atomic_bool
joined
;
vector
<
shared_ptr
<
thread
>>
threadpool
;
recursive_mutex
threadPoolMutex
;
uint64_t
numThreads
=
0
;
Agent
*
agent
=
nullptr
;
protected
:
WorkerThreadPool
(
uint64_t
_numThreads
,
Agent
*
_agent
);
public
:
virtual
~
WorkerThreadPool
();
virtual
void
startService
();
void
joinAll
();
bool
isJoined
()
const
;
};
Write
Preview
Markdown
is supported
0%
Try again
or
attach a new file
Attach a file
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Cancel
Please
register
or
sign in
to comment