Skip to content
GitLab
Explore
Sign in
Primary navigation
Search or go to…
Project
jami-daemon
Manage
Activity
Members
Labels
Plan
Issues
Issue boards
Milestones
Iterations
Wiki
Requirements
Code
Repository
Branches
Commits
Tags
Repository graph
Compare revisions
Locked files
Deploy
Releases
Model registry
Monitor
Incidents
Analyze
Value stream analytics
Contributor analytics
Repository analytics
Issue analytics
Insights
Model experiments
Help
Help
Support
GitLab documentation
Compare GitLab plans
Community forum
Contribute to GitLab
Provide feedback
Keyboard shortcuts
?
Snippets
Groups
Projects
Show more breadcrumbs
savoirfairelinux
jami-daemon
Commits
87a35262
Commit
87a35262
authored
3 years ago
by
Adrien Béraud
Browse files
Options
Downloads
Patches
Plain Diff
ThreadLoop: use enum class for ThreadState
Change-Id: I48cf424123ef137dc1c6fee0ab68c94ab6ac4c56
parent
1d4dc978
No related branches found
Branches containing commit
No related tags found
No related merge requests found
Changes
2
Hide whitespace changes
Inline
Side-by-side
Showing
2 changed files
src/threadloop.cpp
+9
-22
9 additions, 22 deletions
src/threadloop.cpp
src/threadloop.h
+4
-4
4 additions, 4 deletions
src/threadloop.h
with
13 additions
and
26 deletions
src/threadloop.cpp
+
9
−
22
View file @
87a35262
...
...
@@ -34,7 +34,7 @@ ThreadLoop::mainloop(std::thread::id& tid,
tid
=
std
::
this_thread
::
get_id
();
try
{
if
(
setup
())
{
while
(
state_
==
RUNNING
)
while
(
state_
==
ThreadState
::
RUNNING
)
process
();
cleanup
();
}
else
{
...
...
@@ -70,28 +70,27 @@ ThreadLoop::start()
{
const
auto
s
=
state_
.
load
();
if
(
s
==
RUNNING
)
{
if
(
s
==
ThreadState
::
RUNNING
)
{
JAMI_ERR
(
"already started"
);
return
;
}
// stop pending but not processed by thread yet?
if
(
s
==
STOPPING
and
thread_
.
joinable
())
{
if
(
s
==
ThreadState
::
STOPPING
and
thread_
.
joinable
())
{
JAMI_DBG
(
"stop pending"
);
thread_
.
join
();
}
state_
=
RUNNING
;
thread_
=
std
::
thread
(
&
ThreadLoop
::
mainloop
,
this
,
std
::
ref
(
threadId_
),
setup_
,
process_
,
cleanup_
);
state_
=
ThreadState
::
RUNNING
;
thread_
=
std
::
thread
(
&
ThreadLoop
::
mainloop
,
this
,
std
::
ref
(
threadId_
),
setup_
,
process_
,
cleanup_
);
threadId_
=
thread_
.
get_id
();
}
void
ThreadLoop
::
stop
()
{
if
(
state_
==
RUNNING
)
state_
=
STOPPING
;
if
(
state_
==
ThreadState
::
RUNNING
)
state_
=
ThreadState
::
STOPPING
;
}
void
...
...
@@ -120,24 +119,12 @@ bool
ThreadLoop
::
isRunning
()
const
noexcept
{
#ifdef _WIN32
return
state_
==
RUNNING
;
return
state_
==
ThreadState
::
RUNNING
;
#else
return
thread_
.
joinable
()
and
state_
==
RUNNING
;
return
thread_
.
joinable
()
and
state_
==
ThreadState
::
RUNNING
;
#endif
}
bool
ThreadLoop
::
isStopping
()
const
noexcept
{
return
state_
==
STOPPING
;
}
std
::
thread
::
id
ThreadLoop
::
get_id
()
const
noexcept
{
return
threadId_
;
}
void
InterruptedThreadLoop
::
stop
()
{
...
...
This diff is collapsed.
Click to expand it.
src/threadloop.h
+
4
−
4
View file @
87a35262
...
...
@@ -40,7 +40,7 @@ struct ThreadLoopException : public std::runtime_error
class
ThreadLoop
{
public:
enum
ThreadState
{
READY
,
RUNNING
,
STOPPING
};
enum
class
ThreadState
{
READY
,
RUNNING
,
STOPPING
};
ThreadLoop
(
const
std
::
function
<
bool
()
>&
setup
,
const
std
::
function
<
void
()
>&
process
,
...
...
@@ -54,8 +54,8 @@ public:
void
waitForCompletion
();
// thread will stop itself
bool
isRunning
()
const
noexcept
;
bool
isStopping
()
const
noexcept
;
std
::
thread
::
id
get_id
()
const
noexcept
;
bool
isStopping
()
const
noexcept
{
return
state_
==
ThreadState
::
STOPPING
;
}
std
::
thread
::
id
get_id
()
const
noexcept
{
return
threadId_
;
}
private
:
ThreadLoop
(
const
ThreadLoop
&
)
=
delete
;
...
...
@@ -73,7 +73,7 @@ private:
const
std
::
function
<
void
()
>
process
,
const
std
::
function
<
void
()
>
cleanup
);
std
::
atomic
<
ThreadState
>
state_
{
READY
};
std
::
atomic
<
ThreadState
>
state_
{
ThreadState
::
READY
};
std
::
thread
::
id
threadId_
;
std
::
thread
thread_
;
};
...
...
This diff is collapsed.
Click to expand it.
Preview
0%
Loading
Try again
or
attach a new file
.
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Save comment
Cancel
Please
register
or
sign in
to comment