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
9b1b6981
Unverified
Commit
9b1b6981
authored
Sep 07, 2021
by
kladko
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
SKALE-4586 Added Thread Pool
parent
d4e26311
Changes
3
Show whitespace changes
Inline
Side-by-side
Showing
3 changed files
with
38 additions
and
30 deletions
+38
-30
WorkerThreadPool.cpp
zmq_src/WorkerThreadPool.cpp
+13
-15
WorkerThreadPool.h
zmq_src/WorkerThreadPool.h
+0
-4
ZMQServer.cpp
zmq_src/ZMQServer.cpp
+25
-11
No files found.
zmq_src/WorkerThreadPool.cpp
View file @
9b1b6981
...
...
@@ -27,41 +27,39 @@
#include "WorkerThreadPool.h"
void
WorkerThreadPool
::
startService
()
{
WorkerThreadPool
::
WorkerThreadPool
(
uint64_t
_numThreads
,
ZMQServer
*
_agent
)
:
joined
(
false
)
{
CHECK_STATE
(
_numThreads
>
0
);
CHECK_STATE
(
_agent
);
CHECK_STATE
(
!
started
.
exchange
(
true
))
spdlog
::
info
(
"Creating thread pool. Threads count:"
+
to_string
(
_numThreads
));
this
->
agent
=
_agent
;
this
->
numThreads
=
_numThreads
;;
LOCK
(
m
)
for
(
uint64_t
i
=
0
;
i
<
(
uint64_t
)
numThreads
;
i
++
)
{
createThread
(
i
);
}
}
spdlog
::
info
(
"Created thread pool"
);
WorkerThreadPool
::
WorkerThreadPool
(
uint64_t
_numThreads
,
ZMQServer
*
_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
(
m
);
spdlog
::
info
(
"Joining worker threads ..."
);
joined
=
true
;
if
(
joined
.
exchange
(
true
))
return
;
for
(
auto
&&
thread
:
threadpool
)
{
if
(
thread
->
joinable
())
thread
->
join
();
CHECK_STATE
(
!
thread
->
joinable
());
}
spdlog
::
info
(
"Joined worker threads."
);
}
bool
WorkerThreadPool
::
isJoined
()
const
{
...
...
zmq_src/WorkerThreadPool.h
View file @
9b1b6981
...
...
@@ -33,8 +33,6 @@ class ZMQServer;
class
WorkerThreadPool
{
atomic_bool
started
;
void
createThread
(
uint64_t
threadNumber
);
recursive_mutex
m
;
...
...
@@ -53,8 +51,6 @@ public:
virtual
~
WorkerThreadPool
();
virtual
void
startService
();
void
joinAll
();
bool
isJoined
()
const
;
...
...
zmq_src/ZMQServer.cpp
View file @
9b1b6981
...
...
@@ -94,10 +94,26 @@ void ZMQServer::run() {
std
::
atomic
<
bool
>
ZMQServer
::
isExitRequested
(
false
);
void
ZMQServer
::
exitZMQServer
()
{
isExitRequested
.
exchange
(
true
);
// if already exited do not exit
spdlog
::
info
(
"exitZMQServer called"
);
if
(
isExitRequested
.
exchange
(
true
))
{
spdlog
::
info
(
"Exit is already under way"
);
return
;
}
spdlog
::
info
(
"Exiting ZMQServer"
);
spdlog
::
info
(
"Joining worker thread pool threads ..."
);
zmqServer
->
threadPool
->
joinAll
();
spdlog
::
info
(
"Joined worker thread pool threads"
);
spdlog
::
info
(
"Shutting down ZMQ contect"
);
zmqServer
->
ctx
->
shutdown
();
spdlog
::
info
(
"Shut down ZMQ contect"
);
spdlog
::
info
(
"Closing ZMQ server socket ..."
);
zmqServer
->
socket
->
close
();
spdlog
::
info
(
"Closed ZMQ server socket"
);
spdlog
::
info
(
"Closing ZMQ context ..."
);
zmqServer
->
ctx
->
close
();
spdlog
::
info
(
"Closed ZMQ context."
);
spdlog
::
info
(
"Exited zmq server."
);
}
...
...
@@ -118,7 +134,7 @@ void ZMQServer::initZMQServer(bool _checkSignature, bool _checkKeyOwnership) {
spdlog
::
info
(
"Read CA."
,
rootCAPath
);
};
spdlog
::
info
(
"Initing zmq server."
);
spdlog
::
info
(
"Initing zmq server
..
."
);
zmqServer
=
make_shared
<
ZMQServer
>
(
_checkSignature
,
_checkKeyOwnership
,
rootCAPath
);
...
...
@@ -126,22 +142,20 @@ void ZMQServer::initZMQServer(bool _checkSignature, bool _checkKeyOwnership) {
serverThread
=
make_shared
<
thread
>
(
std
::
bind
(
&
ZMQServer
::
run
,
ZMQServer
::
zmqServer
));
serverThread
->
detach
();
zmqServer
->
releaseWorkers
();
spdlog
::
info
(
"Inited zmq server."
);
spdlog
::
info
(
"Starting zmq server ..."
);
spdlog
::
info
(
"Releasing SGX worker threads ..."
);
zmqServer
->
releaseWorkers
();
spdlog
::
info
(
"Started zmq server."
);
spdlog
::
info
(
"Released SGX worker threads."
);
spdlog
::
info
(
"Inited zmq server."
);
}
shared_ptr
<
std
::
thread
>
ZMQServer
::
serverThread
=
nullptr
;
ZMQServer
::~
ZMQServer
()
{}
ZMQServer
::~
ZMQServer
()
{
exitZMQServer
();
}
void
ZMQServer
::
doOneServerLoop
()
{
...
...
@@ -265,7 +279,7 @@ void ZMQServer::workerThreadMessageProcessLoop(ZMQServer* _agent ) {
_agent
->
waitOnGlobalStartBarrier
();
// do work forever until told to exit
while
(
!
isExitRequested
)
{
sleep
(
1
000
);
usleep
(
1000
000
);
cerr
<<
"WORKER LOOP"
<<
endl
;
}
}
\ No newline at end of file
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