Skip to content
GitLab
Menu
Projects
Groups
Snippets
Help
Help
Support
Community forum
Keyboard shortcuts
?
Submit feedback
Contribute to GitLab
Sign in
Toggle navigation
Menu
Open sidebar
Florian Fischer
emper
Commits
840e1f14
Commit
840e1f14
authored
Apr 26, 2022
by
Florian Fischer
Browse files
add emper::nanosleep similar to nanosleep(3)
parent
f442e1fd
Changes
2
Hide whitespace changes
Inline
Side-by-side
emper/Emper.cpp
View file @
840e1f14
...
...
@@ -5,6 +5,7 @@
#include
<cassert>
#include
<cerrno>
#include
<cstdint>
#include
<ctime>
#include
<stdexcept>
#include
<utility>
...
...
@@ -182,16 +183,25 @@ void yield() {
runtime
->
yield
();
}
auto
sleep
(
unsigned
int
second
s
)
->
bool
{
static
auto
_
sleep
(
emper
::
io
::
AlarmFuture
::
Timespec
&
t
s
)
->
bool
{
if
constexpr
(
!
emper
::
IO
)
{
DIE_MSG
(
"sleep requires emper::io"
);
}
emper
::
io
::
AlarmFuture
::
Timespec
ts
=
{.
tv_sec
=
seconds
,
.
tv_nsec
=
0
};
emper
::
io
::
AlarmFuture
alarm
(
ts
);
int32_t
res
=
alarm
.
submitAndWait
();
return
res
==
-
ETIME
;
}
auto
sleep
(
unsigned
int
seconds
)
->
bool
{
emper
::
io
::
AlarmFuture
::
Timespec
ts
=
{.
tv_sec
=
seconds
,
.
tv_nsec
=
0
};
return
_sleep
(
ts
);
}
auto
nanosleep
(
const
struct
timespec
*
rqtp
)
->
bool
{
emper
::
io
::
AlarmFuture
::
Timespec
ts
=
{.
tv_sec
=
rqtp
->
tv_sec
,
.
tv_nsec
=
rqtp
->
tv_nsec
};
return
_sleep
(
ts
);
}
}
// namespace emper
emper/include/emper.hpp
View file @
840e1f14
...
...
@@ -56,5 +56,6 @@ void destroy_runtime();
void
yield
();
auto
sleep
(
unsigned
int
seconds
)
->
bool
;
auto
nanosleep
(
const
struct
timespec
*
rqtp
)
->
bool
;
}
// namespace emper
Write
Preview
Supports
Markdown
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