Commit 840e1f14 authored by Florian Fischer's avatar Florian Fischer
Browse files

add emper::nanosleep similar to nanosleep(3)

parent f442e1fd
......@@ -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 seconds) -> bool {
static auto _sleep(emper::io::AlarmFuture::Timespec& ts) -> 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
......@@ -56,5 +56,6 @@ void destroy_runtime();
void yield();
auto sleep(unsigned int seconds) -> bool;
auto nanosleep(const struct timespec* rqtp) -> bool;
} // namespace emper
Supports Markdown
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment