Skip to content

Commit d779cd8

Browse files
committed
[fiber] Add empty polyfill when not enabled
1 parent ac2a6c9 commit d779cd8

File tree

3 files changed

+57
-3
lines changed

3 files changed

+57
-3
lines changed

src/modm/processing/fiber.hpp

Lines changed: 20 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
/*
2-
* Copyright (c) 2020, Erik Henriksson
2+
* Copyright (c) 2024, Niklas Hauser
33
*
44
* This file is part of the modm project.
55
*
@@ -9,5 +9,22 @@
99
*/
1010
// ----------------------------------------------------------------------------
1111

12-
#include "fiber/functions.hpp"
13-
#include "fiber/task.hpp"
12+
/*
13+
We use __has_include guards here to support the case when fibers are not in use
14+
but we still need to provide the interface to the rest of the library.
15+
Then only the functionality that is enabled is supported and the fiber yield()
16+
function returns immediately, thus blocks in-place.
17+
*/
18+
19+
// includes the functions related to time
20+
#if __has_include(<modm/architecture/interface/clock.hpp>)
21+
# include "fiber/functions.hpp"
22+
#endif
23+
// polyfill implementation of an empty yield
24+
#if __has_include("fiber/no_yield.hpp")
25+
# include "fiber/no_yield.hpp"
26+
#endif
27+
// pulls in the fiber and scheduler implementation
28+
#if __has_include("fiber/task.hpp")
29+
# include "fiber/task.hpp"
30+
#endif
Lines changed: 31 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,31 @@
1+
/*
2+
* Copyright (c) 2023, Niklas Hauser
3+
*
4+
* This file is part of the modm project.
5+
*
6+
* This Source Code Form is subject to the terms of the Mozilla Public
7+
* License, v. 2.0. If a copy of the MPL was not distributed with this
8+
* file, You can obtain one at http://mozilla.org/MPL/2.0/.
9+
*/
10+
// ----------------------------------------------------------------------------
11+
12+
#pragma once
13+
14+
/// @cond
15+
namespace modm::this_fiber
16+
{
17+
18+
void inline
19+
yield()
20+
{
21+
// do nothing and return
22+
}
23+
24+
modm::fiber::id inline
25+
get_id()
26+
{
27+
return 0;
28+
}
29+
30+
} // namespace modm::this_fiber
31+
/// @endcond

src/modm/processing/module.lb

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -27,6 +27,12 @@ def build(env):
2727
env.outbasepath = "modm/src/modm/processing"
2828
env.copy("task.hpp")
2929

30+
if not env.has_module(":processing:fiber"):
31+
env.outbasepath = "modm/src/modm/processing/"
32+
env.copy("fiber/functions.hpp")
33+
env.copy("fiber/no_yield.hpp")
34+
env.copy("fiber.hpp")
35+
3036
env.outbasepath = "modm/src/modm"
3137
headers = env.generated_local_files(filterfunc=lambda path: ".h" in path and not "_impl.h" in path)
3238
env.template("processing.hpp.in", substitutions={"headers": sorted(headers)})

0 commit comments

Comments
 (0)