forked from modm-io/modm
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
[fiber] Implement resumable functions as fibers
Add experimental option for implementing resumable functions in terms of fibers.
- Loading branch information
1 parent
77a761d
commit 5f3c900
Showing
4 changed files
with
152 additions
and
7 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,59 @@ | ||
/* | ||
* Copyright (c) 2021, Christopher Durand | ||
* | ||
* This file is part of the modm project. | ||
* | ||
* This Source Code Form is subject to the terms of the Mozilla Public | ||
* License, v. 2.0. If a copy of the MPL was not distributed with this | ||
* file, You can obtain one at http://mozilla.org/MPL/2.0/. | ||
*/ | ||
// ---------------------------------------------------------------------------- | ||
|
||
#ifndef MODM_RF_MACROS_HPP | ||
#define MODM_RF_MACROS_HPP | ||
|
||
#include <modm/architecture/interface/assert.hpp> | ||
#include <modm/architecture/utils.hpp> | ||
#include <modm/processing/fiber/scheduler.hpp> | ||
|
||
/// @ingroup modm_processing_resumable | ||
/// @{ | ||
|
||
#define RF_BEGIN(index) | ||
|
||
#define RF_BEGIN() | ||
|
||
#define RF_END_RETURN(...) return __VA_ARGS__ | ||
|
||
#define RF_END() | ||
|
||
#define RF_END_RETURN(...) return __VA_ARGS__ | ||
|
||
#define RF_YIELD() modm::fiber::yield() | ||
|
||
#define RF_WAIT_WHILE(...) \ | ||
do { \ | ||
while (__VA_ARGS__) { \ | ||
modm::fiber::yield(); \ | ||
} \ | ||
} while(0) | ||
|
||
#define RF_WAIT_UNTIL(...) \ | ||
RF_WAIT_WHILE(!(__VA_ARGS__)) | ||
|
||
#define RF_CALL(...) __VA_ARGS__ | ||
|
||
// TODO: implement blocking | ||
#define RF_CALL(...) __VA_ARGS__ | ||
|
||
#define RF_RETURN_CALL(...) return __VA_ARGS__ | ||
|
||
#define RF_RETURN(...) return __VA_ARGS__ | ||
|
||
#define RF_RETURN() return | ||
|
||
/// @} | ||
|
||
#endif | ||
|
||
#endif // MODM_RF_MACROS_HPP |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,33 @@ | ||
/* | ||
* Copyright (c) 2021, Christopher Durand | ||
* | ||
* This file is part of the modm project. | ||
* | ||
* This Source Code Form is subject to the terms of the Mozilla Public | ||
* License, v. 2.0. If a copy of the MPL was not distributed with this | ||
* file, You can obtain one at http://mozilla.org/MPL/2.0/. | ||
*/ | ||
// ---------------------------------------------------------------------------- | ||
|
||
#ifndef MODM_NESTED_RESUMABLE_HPP | ||
#define MODM_NESTED_RESUMABLE_HPP | ||
|
||
#include "macros.hpp" | ||
#include <cstdint> | ||
|
||
namespace modm | ||
{ | ||
|
||
/** | ||
* Dummy implementation to be used with fibers | ||
* | ||
* @ingroup modm_processing_resumable | ||
*/ | ||
template<uint8_t Levels = 1> | ||
class NestedResumable | ||
{}; | ||
/// @endcond | ||
|
||
} // namespace modm | ||
|
||
#endif // MODM_NESTED_RESUMABLE_HPP |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,40 @@ | ||
/* | ||
* Copyright (c) 2021, Christopher Durand | ||
* | ||
* This file is part of the modm project. | ||
* | ||
* This Source Code Form is subject to the terms of the Mozilla Public | ||
* License, v. 2.0. If a copy of the MPL was not distributed with this | ||
* file, You can obtain one at http://mozilla.org/MPL/2.0/. | ||
*/ | ||
// ---------------------------------------------------------------------------- | ||
|
||
#ifndef MODM_RESUMABLE_HPP | ||
#define MODM_RESUMABLE_HPP | ||
|
||
#include "macros.hpp" | ||
#include <cstdint> | ||
|
||
namespace modm | ||
{ | ||
|
||
/** | ||
* Dummy implementation to be used with fibers | ||
* | ||
* @ingroup modm_processing_resumable | ||
*/ | ||
template <typename T> | ||
using ResumableResult = T; | ||
|
||
/** | ||
* Dummy implementation to be used with fibers | ||
* | ||
* @ingroup modm_processing_resumable | ||
*/ | ||
template<uint8_t Functions = 1> | ||
class Resumable | ||
{}; | ||
|
||
} // namespace modm | ||
|
||
#endif // MODM_RESUMABLE_HPP |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters