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

Merge branch 'emper-sleep-in-module' into 'master'

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

See merge request !231
parents 96d27755 e2266980
No related branches found
No related tags found
1 merge request!231Move emper::sleep() implemention from header in compilation unit
Pipeline #67081 passed
// SPDX-License-Identifier: LGPL-3.0-or-later // SPDX-License-Identifier: LGPL-3.0-or-later
// Copyright © 2020 Florian Schmaus // Copyright © 2020-2021 Florian Schmaus
#include "Emper.hpp" #include "Emper.hpp"
#include <cerrno>
#include <cstdint>
#include <stdexcept> #include <stdexcept>
#include "Common.hpp"
#include "Runtime.hpp" #include "Runtime.hpp"
#include "emper-common.h" #include "emper-common.h"
#include "emper-version.h" #include "emper-version.h"
#include "io/Future.hpp"
namespace emper { namespace emper {
...@@ -44,4 +48,16 @@ void destroy_runtime() { ...@@ -44,4 +48,16 @@ void destroy_runtime() {
delete 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 } // namespace emper
// SPDX-License-Identifier: LGPL-3.0-or-later // SPDX-License-Identifier: LGPL-3.0-or-later
// Copyright © 2020 Florian Schmaus // Copyright © 2020-2021 Florian Schmaus
#pragma once #pragma once
#include <cassert> #include <cassert>
...@@ -10,7 +10,6 @@ ...@@ -10,7 +10,6 @@
#include "Fiber.hpp" #include "Fiber.hpp"
#include "Runtime.hpp" #include "Runtime.hpp"
#include "SynchronizedFiber.hpp" #include "SynchronizedFiber.hpp"
#include "io/Future.hpp"
void async(Fiber* fiber) { void async(Fiber* fiber) {
assert(fiber != nullptr); assert(fiber != nullptr);
...@@ -75,16 +74,6 @@ void yield() { ...@@ -75,16 +74,6 @@ void yield() {
runtime->yield(); runtime->yield();
} }
auto sleep(unsigned int seconds) -> bool { 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 } // 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