Skip to content
Snippets Groups Projects
Commit e2266980 authored by Florian Schmaus's avatar Florian Schmaus
Browse files

Move emper::sleep() implemention from header in compilation unit

parent 96d27755
No related branches found
No related tags found
No related merge requests found
// SPDX-License-Identifier: LGPL-3.0-or-later
// Copyright © 2020 Florian Schmaus
// Copyright © 2020-2021 Florian Schmaus
#include "Emper.hpp"
#include <cerrno>
#include <cstdint>
#include <stdexcept>
#include "Common.hpp"
#include "Runtime.hpp"
#include "emper-common.h"
#include "emper-version.h"
#include "io/Future.hpp"
namespace emper {
......@@ -44,4 +48,16 @@ void destroy_runtime() {
delete runtime;
}
auto sleep(unsigned int seconds) -> 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;
}
} // namespace emper
// SPDX-License-Identifier: LGPL-3.0-or-later
// Copyright © 2020 Florian Schmaus
// Copyright © 2020-2021 Florian Schmaus
#pragma once
#include <cassert>
......@@ -10,7 +10,6 @@
#include "Fiber.hpp"
#include "Runtime.hpp"
#include "SynchronizedFiber.hpp"
#include "io/Future.hpp"
void async(Fiber* fiber) {
assert(fiber != nullptr);
......@@ -75,16 +74,6 @@ void yield() {
runtime->yield();
}
auto sleep(unsigned int seconds) -> 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;
} // namespace emper
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment