Skip to content
Snippets Groups Projects
Commit d8a6ade9 authored by Florian Fischer's avatar Florian Fischer
Browse files

[Future] remove not used rvalue reference setCallback

parent 388bd882
No related branches found
No related tags found
No related merge requests found
Pipeline #61849 passed
......@@ -56,10 +56,7 @@ class Future : public Logger<LogSubsystem::IO> {
public:
workeraffinity_t affinity;
// store callback via copy
CallbackInternal(Callback callback) : callback(std::move(callback)) {}
// store callback via move
CallbackInternal(const Callback&& callback) : callback(callback) {}
void operator()(const int32_t& res) { callback(res); }
};
......@@ -247,32 +244,17 @@ class Future : public Logger<LogSubsystem::IO> {
this->dependency = &dependency;
}
private:
inline void setCallback(CallbackInternal* callback) {
if (unlikely(this->callback)) {
delete this->callback;
}
this->callback = callback;
}
public:
/*
* @brief register a callback which is executed in a new Fiber on completion
*
* @param callback Callback reference which is copied and executed on completion.
* It gets passed the value causing the completion.
*/
inline void setCallback(const Callback& callback) { setCallback(new CallbackInternal(callback)); }
/*
* @brief register a callback which is executed in a new Fiber on completion
*
* @param callback Callback rvalue which gets moved and executed on completion.
* It gets passed the value causing the completion.
*/
inline void setCallback(const Callback&& callback) {
setCallback(new CallbackInternal(callback));
inline void setCallback(const Callback& callback) {
if (unlikely(this->callback)) {
delete this->callback;
}
this->callback = new CallbackInternal(callback);
}
/*
......
......@@ -10,17 +10,15 @@
using emper::io::AlarmFuture;
using emper::io::Future;
void callback(int32_t res, BPS& bps) {
assert(res == -ETIME);
bps.signal();
}
void emperTest() {
AlarmFuture::Timespec ts = {.tv_sec = 1, .tv_nsec = 0};
AlarmFuture alarm(ts);
BPS bps;
alarm.setCallback(Future::Callback([&bps](int32_t res) { callback(res, bps); }));
alarm.setCallback([&bps](int32_t res) {
assert(res == -ETIME);
bps.signal();
});
alarm.submit();
// wait till the callback was executed
......
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