Skip to content
GitLab
Explore
Sign in
Primary navigation
Search or go to…
Project
opendht
Manage
Activity
Members
Labels
Plan
Issues
Issue boards
Milestones
Iterations
Code
Repository
Branches
Commits
Tags
Repository graph
Compare revisions
Locked files
Deploy
Model registry
Analyze
Model experiments
Help
Help
Support
GitLab documentation
Compare GitLab plans
GitLab community forum
Contribute to GitLab
Provide feedback
Keyboard shortcuts
?
Snippets
Groups
Projects
Show more breadcrumbs
savoirfairelinux
opendht
Commits
77750543
Commit
77750543
authored
6 years ago
by
Adrien Béraud
Browse files
Options
Downloads
Patches
Plain Diff
tools: always handle signals, don't block in signal handling
parent
18c31612
No related branches found
No related tags found
No related merge requests found
Changes
2
Show whitespace changes
Inline
Side-by-side
Showing
2 changed files
tools/dhtnode.cpp
+3
-4
3 additions, 4 deletions
tools/dhtnode.cpp
tools/tools_common.h
+2
-5
2 additions, 5 deletions
tools/tools_common.h
with
5 additions
and
9 deletions
tools/dhtnode.cpp
+
3
−
4
View file @
77750543
...
@@ -503,9 +503,8 @@ main(int argc, char **argv)
...
@@ -503,9 +503,8 @@ main(int argc, char **argv)
if
(
params
.
daemonize
)
{
if
(
params
.
daemonize
)
{
daemonize
();
daemonize
();
}
else
if
(
params
.
service
)
{
setupSignals
();
}
}
setupSignals
();
auto
node
=
std
::
make_shared
<
DhtRunner
>
();
auto
node
=
std
::
make_shared
<
DhtRunner
>
();
...
@@ -576,7 +575,7 @@ main(int argc, char **argv)
...
@@ -576,7 +575,7 @@ main(int argc, char **argv)
std
::
condition_variable
cv
;
std
::
condition_variable
cv
;
std
::
mutex
m
;
std
::
mutex
m
;
std
::
atomic_
bool
done
{
false
};
bool
done
{
false
};
node
->
shutdown
([
&
]()
node
->
shutdown
([
&
]()
{
{
...
@@ -587,7 +586,7 @@ main(int argc, char **argv)
...
@@ -587,7 +586,7 @@ main(int argc, char **argv)
// wait for shutdown
// wait for shutdown
std
::
unique_lock
<
std
::
mutex
>
lk
(
m
);
std
::
unique_lock
<
std
::
mutex
>
lk
(
m
);
cv
.
wait
(
lk
,
[
&
](){
return
done
.
load
()
;
});
cv
.
wait
(
lk
,
[
&
](){
return
done
;
});
node
->
join
();
node
->
join
();
#ifdef WIN32_NATIVE
#ifdef WIN32_NATIVE
...
...
This diff is collapsed.
Click to expand it.
tools/tools_common.h
+
2
−
5
View file @
77750543
...
@@ -282,18 +282,17 @@ readLine(const char* prefix = PROMPT)
...
@@ -282,18 +282,17 @@ readLine(const char* prefix = PROMPT)
struct
ServiceRunner
{
struct
ServiceRunner
{
bool
wait
()
{
bool
wait
()
{
std
::
unique_lock
<
std
::
mutex
>
lock
(
m
);
std
::
unique_lock
<
std
::
mutex
>
lock
(
m
);
cv
.
wait
(
lock
,
[
&
]{
return
terminate
;});
cv
.
wait
(
lock
,
[
&
]{
return
terminate
.
load
()
;});
return
!
terminate
;
return
!
terminate
;
}
}
void
kill
()
{
void
kill
()
{
std
::
lock_guard
<
std
::
mutex
>
lock
(
m
);
terminate
=
true
;
terminate
=
true
;
cv
.
notify_all
();
cv
.
notify_all
();
}
}
private
:
private
:
std
::
condition_variable
cv
;
std
::
condition_variable
cv
;
std
::
mutex
m
;
std
::
mutex
m
;
bool
terminate
=
false
;
std
::
atomic_
bool
terminate
{
false
}
;
};
};
ServiceRunner
runner
;
ServiceRunner
runner
;
...
@@ -340,7 +339,5 @@ void daemonize()
...
@@ -340,7 +339,5 @@ void daemonize()
close
(
STDIN_FILENO
);
close
(
STDIN_FILENO
);
close
(
STDOUT_FILENO
);
close
(
STDOUT_FILENO
);
close
(
STDERR_FILENO
);
close
(
STDERR_FILENO
);
setupSignals
();
#endif
#endif
}
}
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